GCC Code Coverage Report


Directory: ./
File: sql/mysqld.cc
Date: 2022-12-13 11:44:05
Exec Total Coverage
Lines: 3579 4153 86.2%
Branches: 3893 8978 43.4%

Line Branch Exec Source
1 /* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23 /**
24 @file sql/mysqld.cc
25 MySQL server daemon.
26 */
27
28 /* clang-format off */
29 /**
30 @mainpage Welcome
31
32 Welcome to the MySQL source code documentation.
33
34 This documentation covers primarily the MySQL server,
35 for the @c mysqld process.
36
37 Other programs, like the MySQL Router, are also documented,
38 see the @ref PAGE_SERVER_TOOLS section.
39
40 The order chosen to present the content is to start with low level components,
41 and build upon previous sections, so that code is presented in a logical order.
42
43 For some sections, a full article (Doxygen 'page') presents the component in detail.
44
45 For other sections, only links are provided, as a starting point into the component.
46
47 For the user manual, see http://dev.mysql.com/doc/refman/8.0/en/
48
49 For the internals manual, see https://dev.mysql.com/doc/internals/en/index.html
50
51 This documentation is published for each release, starting with MySQL 8.0.
52
53 The present document corresponds to:
54
55 Document generated on: ${DOXYGEN_GENERATION_DATE},
56 branch: ${DOXYGEN_GENERATION_BRANCH},
57 revision: ${DOXYGEN_GENERATION_REVISION}
58
59 For the latest available version, see https://dev.mysql.com/doc/dev/mysql-server/latest/
60
61 For other versions, see https://dev.mysql.com/doc/index-archive.html
62 */
63
64 /**
65 @page PAGE_GET_STARTED Getting Started
66
67 - @ref start_source
68 - @subpage PAGE_CODING_GUIDELINES
69 - @ref start_debug
70
71 @section start_source Build from source
72
73 See https://dev.mysql.com/doc/refman/8.0/en/source-installation.html
74
75 @section start_debug Debugging
76
77 The easiest way to install a server, and attach a debugger to it,
78 is to start the mysql-test-run (MTR) tool with debugging options
79
80 @verbatim
81 cd mysql-test
82 ./mtr --ddd main.parser
83 @endverbatim
84
85 The following functions are good candidates for breakpoints:
86 - #my_message_sql
87 - #dispatch_command
88
89 Replace 'main.parser' with another test script, or write your own, to debug a specific area.
90 */
91
92 /**
93 @page PAGE_CODING_GUIDELINES Coding Guidelines
94
95 This section shows the guidelines that MySQL developers
96 follow when writing new code.
97
98 New MySQL code uses the Google C++ coding style
99 (https://google.github.io/styleguide/cppguide.html), with two
100 exceptions:
101
102 - Member variable names: Do not use foo_. Instead, use
103 m_foo (non-static) or s_foo (static).
104
105 - Do not use non-const references as function parameters, even if they
106 are optional. Instead, use pointers for in/out and output parameters.
107 (This matches an older version of the Google style guide.) Do not use
108 references, whether const or non-const, as struct or class members.
109
110 Old projects and modifications to old code use an older MySQL-specific
111 style for the time being. Since 8.0, MySQL style uses the same formatting
112 rules as Google coding style (e.g., brace placement, indentation, line
113 lengths, etc.), but differs in a few important aspects:
114
115 - Class names: Do not use MyClass. Instead, use My_class.
116
117 - Function names: Use snake_case().
118
119 - Comment Style: Use either the // or <em>/</em>* *<em>/</em> syntax. // is
120 much more common but both syntaxes are permitted for the time being.
121
122 - Doxygen comments: Use <em>/</em>** ... *<em>/</em> syntax and not ///.
123
124 - Doxygen commands: Use '@' and not '\' for doxygen commands.
125
126 - You may see structs starting with st_ and being typedef-ed to some
127 UPPERCASE (e.g. typedef struct st_foo { ... } FOO). However,
128 this is legacy from when the codebase contained C. Do not make such new
129 typedefs nor structs with st_ prefixes, and feel free to remove those that
130 already exist, except in public header files that are part of libmysql
131 (which need to be parseable as C99).
132
133
134 Code formatting is enforced by use of clang-format throughout the code
135 base. However, note that formatting is only one part of coding style;
136 you are required to take care of non-formatting issues yourself, such as
137 following naming conventions, having clear ownership of code or minimizing
138 the use of macros. See the Google coding style guide for the entire list.
139
140 Consistent style is important for us, because everyone must know what to
141 expect. Knowing our rules, you'll find it easier to read our code, and when
142 you decide to contribute (which we hope you'll consider!) we'll find it
143 easier to read and review your code.
144
145 - @subpage GENERAL_DEVELOPMENT_GUIDELINES
146 - @subpage CPP_CODING_GUIDELINES_FOR_NDB_SE
147 - @subpage DBUG_TAGS
148
149 */
150
151 /**
152 @page PAGE_INFRASTRUCTURE Infrastructure
153
154 @section infra_basic Basic classes and templates
155
156 @subsection infra_basic_container Container
157
158 See #DYNAMIC_ARRAY, #List, #I_P_List, #LF_HASH.
159
160 @subsection infra_basic_syncho Synchronization
161
162 See #native_mutex_t, #native_rw_lock_t, #native_cond_t.
163
164 @subsection infra_basic_fileio File IO
165
166 See #my_open, #my_dir.
167
168 @section infra_server_blocks Server building blocks
169
170 @subsection infra_server_blocks_vio Virtual Input Output
171
172 See #Vio, #vio_init.
173
174 @section deployment Deployment
175
176 @subsection deploy_install Installation
177
178 See #opt_initialize, #bootstrap::run_bootstrap_thread.
179
180 @subsection deploy_startup Startup
181
182 See #mysqld_main.
183
184 @subsection deploy_shutdown Shutdown
185
186 See #handle_fatal_signal, #signal_hand.
187
188 @subsection deploy_upgrade Upgrade
189
190 See #Mysql::Tools::Upgrade::Program.
191
192 */
193
194 /**
195 @page PAGE_PROTOCOL Client/Server Protocol
196
197 @section protocol_overview Overview
198
199 The MySQL protocol is used between MySQL Clients and a MySQL Server.
200 It is implemented by:
201 - Connectors (Connector/C, Connector/J, and so forth)
202 - MySQL Proxy
203 - Communication between master and slave replication servers
204
205 The protocol supports these features:
206 - Transparent encryption using SSL
207 - Transparent compression
208 - A @ref page_protocol_connection_phase where capabilities and
209 authentication data are exchanged
210 - A @ref page_protocol_command_phase which accepts commands
211 from the client and executes them
212
213 Further reading:
214 - @subpage page_protocol_basics
215 - @subpage page_protocol_connection_lifecycle
216 */
217
218 /** @page page_mysqlx_protocol X %Protocol
219
220 @par Topics in this section:
221
222 - @subpage mysqlx_protocol_lifecycle
223 - @subpage mysqlx_protocol_authentication
224 - @subpage mysqlx_protocol_messages
225 - @subpage mysqlx_protocol_expectations
226 - @subpage mysqlx_protocol_notices
227 - @subpage mysqlx_protocol_xplugin
228 - @subpage mysqlx_protocol_use_cases
229 - @subpage mysqlx_protocol_implementation
230 - @subpage mysqlx_protocol_comparison
231 - @subpage mysqlx_community_connector
232
233 The X %Protocol is implemented by the X Plugin and the following
234 MySQL clients support the protocol:
235
236 - MYSQLXSHELL
237
238 - MySQL for Visual Studio 2.0.2 or higher
239
240 - MySQL Connector/J 6.0.2 or higher
241
242 - MySQL Connector/Net 7.0.2 or higher
243
244 - MySQL Connector/Node.js
245 */
246
247
248 /**
249 @page PAGE_SQL_EXECUTION SQL Query Execution
250
251 @section sql_query_exec_parsing SQL Parsing
252
253 The parser processes SQL strings and builds a tree representation of them.
254
255 See @ref GROUP_PARSER.
256
257 @subpage PAGE_SQL_Optimizer
258
259 @subpage stored_programs
260
261 @section sql_query_exec_prepared Prepared statements
262
263 See #mysql_stmt_prepare
264
265 @section func_stored_proc Stored procedures
266
267 See #sp_head, #sp_instr.
268
269 @section sql_query_exec_sql_functions SQL Functions
270
271 See #Item_func
272
273 @section sql_query_exec_error_handling Error handling
274
275 See #my_message, #my_error
276
277 @subpage PAGE_TXN
278
279 */
280
281 /**
282 @page PAGE_STORAGE Data Storage
283
284 @section storage_innodb Innodb
285
286 See #ha_innobase or read details about InnoDB internals:
287 - @subpage PAGE_INNODB_PFS
288 - @subpage PAGE_INNODB_REDO_LOG
289 - @subpage PAGE_INNODB_LOCK_SYS
290 - @subpage PAGE_INNODB_UTILS
291
292 @section storage_temptable Temp table
293
294 Before 8.0, temporary tables were handled by heap engine.
295 The heap engine had no feature to store bigger tables on disk.
296
297 Since 8.0, there is a brand new temptable engine, which
298 is written from scratch using c++11. It has following advantages:
299 - it is able to store bigger tables on disk (in temporary files),
300 - it uses row format with variable size (can save memory for varchars),
301 - it is better designed (easier to maintain).
302
303 @subpage PAGE_TEMPTABLE
304
305 */
306
307
308 /**
309 @page PAGE_REPLICATION Replication
310
311 @subpage PAGE_RPL_FIELD_METADATA
312
313 */
314
315 /**
316 @page PAGE_TXN Transactions
317
318 See #trans_begin, #trans_commit, #trans_rollback.
319 */
320
321 /**
322 @page PAGE_SECURITY Security
323
324 @subpage AUTHORIZATION_PAGE
325 @subpage PAGE_KEYRING_COMPONENT
326 */
327
328
329 /**
330 @page PAGE_MONITORING Monitoring
331
332 @subpage PAGE_PFS
333 */
334
335 /**
336 @page PAGE_EXTENDING Extending MySQL
337
338 Components
339 ----------
340
341 MySQL 8.0 introduces support for extending the server through components.
342 Components can communicate with other components through service APIs.
343 And can provide implementations of service APIs for other components to use.
344 All components are equal and can communicate with all other components.
345 Service implementations can be found by name via a registry service handle
346 which is passed to the component initialization function.
347 There can be multiple service API implementations for a single service API.
348 One of them is the default implementation.
349 Service API are stateless by definition. If they need to handle state or
350 object instances they need to do so by using factory methods and instance
351 handles.
352
353 To ease up transition to the component model the current server
354 functionality (server proper and plugins) is contained within
355 a dedicated built in server component. The server component currently
356 contains all of the functionality provided by the server and
357 classical server plugins.
358
359 More components can be installed via the "INSTALL COMPONENT" SQL command.
360
361 The component infrastructure is designed as a replacement for the classical
362 MySQL plugin system as it does not suffer from some of the limitations of it
363 and provides better isolation for the component code.
364
365 See @subpage PAGE_COMPONENTS.
366
367 Plugins and Services
368 --------------------
369
370 As of MySQL 5.1 the server functionality can be extended through
371 installing (dynamically or statically linked) extra code modules
372 called plugins.
373
374 The server defines a set of well known plugin APIs that the modules
375 can implement.
376
377 To allow plugins to reuse server code the server exposes a pre-defined
378 set of functions to plugins called plugin services.
379
380 See the following for more details:
381 - @subpage page_ext_plugins
382 - @subpage page_ext_plugin_services
383
384
385 User Defined Functions
386 ----------------------
387
388 Native code user defined functions can be added to MySQL server using
389 the CREATE FUNCTION ... SONAME syntax.
390
391 These can co-exit with @ref page_ext_plugins or reside in their own
392 separate binaries.
393
394 To learn how to create these user defined functions see @subpage page_ext_udf
395 */
396
397
398 /**
399 @page PAGE_SERVICES Available services
400
401 @subpage PAGE_TABLE_ACCESS_SERVICE
402 */
403
404
405 /**
406 @page PAGE_SERVER_TOOLS Server tools
407
408 - @subpage PAGE_MYSQL_ROUTER
409 */
410
411
412 /**
413 @page PAGE_CLIENT_TOOLS Client tools
414
415 See mysqldump.cc mysql.cc
416 */
417
418
419 /**
420 @page PAGE_TESTING_TOOLS Testing Tools
421
422 - @subpage PAGE_MYSQL_TEST_RUN
423 */
424
425 /**
426 @page PAGE_DEV_TOOLS Development Tools
427
428 - @subpage PAGE_LOCK_ORDER
429 */
430
431 /**
432 @page PAGE_CODE_PATHS Code paths
433
434 This section details how the server executes some statements,
435 to illustrate how different parts work together.
436
437 Note that this overall view might take some shortcuts,
438 hiding some details or taking liberties with the notations,
439 to present the whole code structure in a comprehensible way.
440
441 - @subpage CODE_PATH_CREATE_TABLE
442 */
443
444 /**
445 @page CODE_PATH_CREATE_TABLE CREATE TABLE
446
447 @section CREATE_TABLE_PARSER Parser
448
449 @startuml
450
451 actor ddl as "CREATE TABLE Query"
452 participant server as "MySQL Server"
453 participant parser as "SQL Parser"
454 participant bison as "Bison Parser"
455 participant lexer as "Lexical Scanner"
456 participant pt as "Parse Tree Nodes"
457
458 ddl -> server : DDL QUERY TEXT
459 server -> parser : THD::sql_parser()
460 == Bison parser ==
461 parser -> bison : MYSQLparse()
462 bison -> lexer : MYSQLlex()
463 bison <-- lexer : yylval, yylloc
464 bison -> pt : new
465 activate pt
466 parser <-- pt : Abstract Syntax Tree
467
468 @enduml
469
470 When a query is sent to the server,
471 the first step is to invoke the bison parser
472 to build an Abstract Syntax Tree to represent the query text.
473
474 Assume the following statement:
475 @verbatim
476 CREATE TABLE test.t1 (a int) ENGINE = "INNODB";
477 @endverbatim
478
479 In the bison grammar file, the rule implementing the CREATE TABLE
480 statement is @c create_table_stmt.
481
482 The tree created is an object of class @ref PT_create_table_stmt.
483
484 This parse tree node has several related nodes, such as:
485 - @ref PT_create_table_option and sub classes, for table options.
486 - @ref PT_table_element and sub classes, for the columns, indexes, etc.
487
488 The collection of nodes returned after the bison parsing is known
489 as the "Abstract Syntax Tree" that represents a SQL query.
490
491 @section CREATE_TABLE_CMD Sql command
492
493 @startuml
494
495 actor ddl as "CREATE TABLE Query"
496 participant server as "MySQL Server"
497 participant parser as "SQL Parser"
498 participant ast as "Abstract Syntax Tree"
499 participant cmd as "SQL Command"
500 participant ci as "HA_CREATE_INFO"
501 participant plugin as "MySQL plugin"
502
503 ddl -> server : DDL QUERY TEXT
504 server -> parser : THD::sql_parser()
505 == Bison parser ==
506 == Build SQL command ==
507 parser -> ast : make_cmd()
508 ast -> ast : contextualize()
509 ast -> ci : build()
510 activate ci
511 ci -> plugin : ha_resolve_engine()
512 ci <-- plugin : storage engine handlerton
513 ast <-- ci : Parse Tree (contextualized)
514 ast -> cmd : build()
515 activate cmd
516 server <-- cmd : SQL Command
517
518 @enduml
519
520 Once the bison parser has finished parsing a query text,
521 the next step is to build a SQL command from the Abstract Syntax Tree.
522
523 In the Abstract Syntax Tree, attributes like a storage engine name
524 ("INNODB") are represented as strings, taken from the query text.
525
526 These attributes need to be converted to objects in the SQL context,
527 such as an @ref innodb_hton pointer to represent the INNODB storage engine.
528
529 The process that performs these transformations is contextualize().
530
531 The @ref Parse_tree_root class is an abstract factory, building @ref Sql_cmd
532 objects.
533
534 For a CREATE TABLE statement, class @ref PT_create_table_stmt builds a
535 concrete @ref Sql_cmd_create_table object.
536
537 @ref PT_create_table_stmt::make_cmd() in particular performs the following
538 actions:
539 - contextualize the parse tree for the CREATE TABLE statement.
540 - build a @ref HA_CREATE_INFO structure to represent the table DDL.
541 - resolve the storage engine name to an actual @ref handlerton pointer,
542 in @ref PT_create_table_engine_option::contextualize()
543
544 @section CREATE_TABLE_RUNTIME Runtime execution
545
546 @startuml
547
548 actor ddl as "CREATE TABLE Query"
549 participant server as "MySQL Server"
550 participant cmd as "SQL Command"
551 participant rt as "Runtime"
552
553 ddl -> server : DDL QUERY TEXT
554 == Bison parser ==
555 == Build SQL command ==
556 == Execute SQL command ==
557 server -> cmd : execute()
558 cmd -> rt : mysql_create_table()
559
560 @enduml
561
562 Execution of a CREATE TABLE statement invokes
563 @ref Sql_cmd_create_table::execute(),
564 which in turns calls:
565 - @ref mysql_create_table(),
566 - @ref mysql_create_table_no_lock(),
567 - @ref create_table_impl(),
568 - @ref rea_create_base_table().
569
570 Execution of this code is the runtime implementation of the CREATE TABLE
571 statement, and eventually leads to:
572 - @ref dd::create_table(), to create the table in the Data Dictionary,
573 - @ref ha_create_table(), to create the table in the handlerton.
574
575 Details about the dictionary and the storage engine are expanded
576 in the following two sections.
577
578
579 @section CREATE_TABLE_DD Data Dictionary
580
581 @startuml
582
583 actor ddl as "CREATE TABLE Query"
584 participant server as "MySQL Server"
585 participant rt as "Runtime"
586 participant dd as "Data Dictionary"
587 participant ddt as "Data Dictionary Table"
588 participant sdi as "Serialized Dictionary Information"
589 participant hton as "Handlerton"
590 participant se as "Storage Engine"
591 participant ts as "Tablespace"
592
593 ddl -> server : DDL QUERY TEXT
594 == ... ==
595 server -> rt : ( execution code path )
596 == Data Dictionary ==
597 rt -> dd : dd::create_table()
598 dd -> ddt : build dd::Table()
599 activate ddt
600 rt <-- ddt : dd:Table instance
601 == Serialized Dictionary Information ==
602 rt -> dd : store()
603 dd -> sdi : dd::sdi::store()
604 sdi -> sdi : sdi_tablespace::store_tbl_sdi()
605 == Storage Engine (Tablespace) ==
606 sdi -> hton : handlerton::sdi()
607 hton -> se : ::sdi() implementation.
608 se -> ts : write metadata in tablespace
609
610 @enduml
611
612 In the data dictionary, creation of a new table calls:
613 - @ref dd::create_dd_user_table()
614 - @ref fill_dd_table_from_create_info()
615
616 The data dictionary code parses the content of the HA_CREATE_INFO
617 input, and builds a @ref dd::Table object, to represent the table metadata.
618 Part of this metadata includes the storage engine name.
619
620 The runtime code then calls @c store() to save this new metadata.
621
622 To store a table metadata, the data dictionary code first serialize it
623 into an sdi format.
624
625 The serialized object is then stored in persistence,
626 either in a tablespace or in a file:
627 - @ref sdi_tablespace::store_tbl_sdi()
628 - @ref sfi_file::store_tbl_sdi()
629
630 When storing data into a tablespace, the storage engine handlerton is
631 invoked, so that the storage engine can ultimately store
632 the table metadata in the tablespace maintained by the storage engine.
633
634 @section CREATE_TABLE_SE Storage Engine
635
636 @startuml
637
638 actor ddl as "CREATE TABLE Query"
639 participant server as "MySQL Server"
640 participant rt as "Runtime"
641 participant sei as "Storage Engine Interface"
642 participant hton as "Storage Engine Handlerton"
643 participant handler as "Storage Engine Handler"
644
645 ddl -> server : DDL QUERY TEXT
646 == ... ==
647 server -> rt : ( execution code path )
648 == Storage Engine (table) ==
649 rt -> sei : ha_create_table()
650 sei -> hton : handlerton::create()
651 hton -> handler : (build a new table handler)
652 activate handler
653 sei <-- handler : storage engine table handler
654 sei -> handler : handler::create()
655
656 @enduml
657
658 When execution of the CREATE TABLE statement
659 reaches the storage engine interface,
660 the SQL layer function @ref ha_create_table()
661 invokes the storage engine @ref handlerton::create()
662 method to instantiate a new storage engine table,
663 represented by @ref handler.
664 The SQL layer then calls @ref handler::create() to create
665 the table inside the storage engine.
666 */
667
668 /**
669 @page PAGE_SQL_Optimizer SQL Optimizer
670
671 The task of query optimizer is to determine the most efficient means for
672 executing queries. The query optimizer consists of the following
673 sub-modules:
674
675 - @ref Query_Resolver
676 - @ref Query_Optimizer
677 - @ref Query_Planner
678 - @ref Query_Executor
679
680 @subpage PAGE_OPT_TRACE
681
682 Additional articles about the query optimizer:
683
684 - @ref PAGE_OPT_TRACE
685 - @ref AGGREGATE_CHECKS
686 */
687 /* clang-format on */
688
689 #include "sql/mysqld.h"
690
691 #include "my_config.h"
692
693 #include "errmsg.h" // init_client_errs
694 #include "ft_global.h"
695 #ifdef _WIN32
696 #include "jemalloc_win.h"
697 #endif
698 #include "keycache.h" // KEY_CACHE
699 #include "libbinlogevents/include/binlog_event.h"
700 #include "libbinlogevents/include/control_events.h"
701 #include "m_string.h"
702 #include "migrate_keyring.h" // Migrate_keyring
703 #include "my_alloc.h"
704 #include "my_base.h"
705 #include "my_bitmap.h" // MY_BITMAP
706 #include "my_command.h"
707 #include "my_compiler.h"
708 #include "my_dbug.h"
709 #include "my_default.h" // print_defaults
710 #include "my_dir.h"
711 #include "my_getpwnam.h"
712 #include "my_loglevel.h"
713 #include "my_macros.h"
714 #include "my_shm_defaults.h" // IWYU pragma: keep
715 #include "my_stacktrace.h" // my_set_exception_pointers
716 #include "my_thread_local.h"
717 #include "my_time.h"
718 #include "my_timer.h" // my_timer_initialize
719 #include "myisam.h"
720 #include "mysql/components/services/bits/psi_bits.h"
721 #include "mysql/components/services/log_builtins.h"
722 #include "mysql/components/services/log_shared.h"
723 #include "mysql/components/services/mysql_runtime_error_service.h"
724 #include "mysql/plugin.h"
725 #include "mysql/plugin_audit.h"
726 #include "mysql/psi/mysql_cond.h"
727 #include "mysql/psi/mysql_file.h"
728 #include "mysql/psi/mysql_memory.h" // mysql_memory_init
729 #include "mysql/psi/mysql_mutex.h"
730 #include "mysql/psi/mysql_rwlock.h"
731 #include "mysql/psi/mysql_socket.h"
732 #include "mysql/psi/mysql_stage.h"
733 #include "mysql/psi/mysql_statement.h"
734 #include "mysql/psi/mysql_thread.h"
735 #include "mysql/psi/psi_cond.h"
736 #include "mysql/psi/psi_data_lock.h"
737 #include "mysql/psi/psi_error.h"
738 #include "mysql/psi/psi_file.h"
739 #include "mysql/psi/psi_idle.h"
740 #include "mysql/psi/psi_mdl.h"
741 #include "mysql/psi/psi_memory.h"
742 #include "mysql/psi/psi_mutex.h"
743 #include "mysql/psi/psi_rwlock.h"
744 #include "mysql/psi/psi_socket.h"
745 #include "mysql/psi/psi_stage.h"
746 #include "mysql/psi/psi_statement.h"
747 #include "mysql/psi/psi_system.h"
748 #include "mysql/psi/psi_table.h"
749 #include "mysql/psi/psi_thread.h"
750 #include "mysql/psi/psi_tls_channel.h"
751 #include "mysql/psi/psi_transaction.h"
752 #include "mysql/service_mysql_alloc.h"
753 #include "mysql/thread_type.h"
754 #include "mysql_com.h"
755 #include "mysql_time.h"
756 #include "mysql_version.h"
757 #include "mysqld_error.h"
758 #include "mysys/buffered_error_log.h"
759 #include "mysys_err.h" // EXIT_OUT_OF_MEMORY
760 #include "pfs_thread_provider.h"
761 #include "print_version.h"
762 #include "scope_guard.h" // create_scope_guard()
763 #include "server_component/log_sink_buffer.h" // log_error_stage_set()
764 #include "server_component/log_sink_perfschema.h" // log_error_read_log()
765 #ifdef _WIN32
766 #include <shellapi.h>
767 #endif
768 #include "sql/auth/auth_common.h" // grant_init
769 #include "sql/auth/sql_authentication.h" // init_rsa_keys
770 #include "sql/auth/sql_security_ctx.h"
771 #include "sql/auto_thd.h" // Auto_THD
772 #include "sql/binlog.h" // mysql_bin_log
773 #include "sql/bootstrap.h" // bootstrap
774 #include "sql/check_stack.h"
775 #include "sql/conn_handler/connection_acceptor.h" // Connection_acceptor
776 #include "sql/conn_handler/connection_handler_impl.h" // Per_thread_connection_handler
777 #include "sql/conn_handler/connection_handler_manager.h" // Connection_handler_manager
778 #include "sql/conn_handler/socket_connection.h" // stmt_info_new_packet
779 #include "sql/current_thd.h" // current_thd
780 #include "sql/dd/cache/dictionary_client.h"
781 #include "sql/debug_sync.h" // debug_sync_end
782 #include "sql/derror.h"
783 #include "sql/event_data_objects.h" // init_scheduler_psi_keys
784 #include "sql/events.h" // Events
785 #include "sql/handler.h"
786 #include "sql/hostname_cache.h" // hostname_cache_init
787 #include "sql/init.h" // unireg_init
788 #include "sql/item.h"
789 #include "sql/item_cmpfunc.h" // Arg_comparator
790 #include "sql/item_create.h"
791 #include "sql/item_func.h"
792 #include "sql/item_strfunc.h" // Item_func_uuid
793 #include "sql/keycaches.h" // get_or_create_key_cache
794 #include "sql/log.h"
795 #include "sql/log_event.h" // Rows_log_event
796 #include "sql/log_resource.h"
797 #include "sql/mdl.h"
798 #include "sql/mdl_context_backup.h" // mdl_context_backup_manager
799 #include "sql/my_decimal.h"
800 #include "sql/mysqld_daemon.h"
801 #include "sql/mysqld_thd_manager.h" // Global_THD_manager
802 #include "sql/opt_costconstantcache.h" // delete_optimizer_cost_module
803 #include "sql/range_optimizer/range_optimizer.h" // range_optimizer_init
804 #include "sql/options_mysqld.h" // OPT_THREAD_CACHE_SIZE
805 #include "sql/partitioning/partition_handler.h" // partitioning_init
806 #include "sql/persisted_variable.h" // Persisted_variables_cache
807 #include "sql/plugin_table.h"
808 #include "sql/protocol.h"
809 #include "sql/psi_memory_key.h" // key_memory_MYSQL_RELAY_LOG_index
810 #include "sql/query_options.h"
811 #include "sql/replication.h" // thd_enter_cond
812 #include "sql/resourcegroups/resource_group_mgr.h" // init, post_init
813 #include "sql/sql_profile.h"
814 #ifdef _WIN32
815 #include "sql/restart_monitor_win.h"
816 #endif
817 #include "sql/rpl_async_conn_failover_configuration_propagation.h"
818 #include "sql/rpl_event_ctx.h" // Rpl_event_ctx
819 #include "sql/rpl_filter.h"
820 #include "sql/rpl_gtid.h"
821 #include "sql/rpl_gtid_persist.h" // Gtid_table_persistor
822 #include "sql/rpl_handler.h" // RUN_HOOK
823 #include "sql/rpl_info_factory.h"
824 #include "sql/rpl_info_handler.h"
825 #include "sql/rpl_injector.h" // injector
826 #include "sql/rpl_io_monitor.h"
827 #include "sql/rpl_log_encryption.h"
828 #include "sql/rpl_source.h" // max_binlog_dump_events
829 #include "sql/rpl_mi.h"
830 #include "sql/rpl_msr.h" // Multisource_info
831 #include "sql/rpl_rli.h" // Relay_log_info
832 #include "sql/rpl_replica.h" // replica_load_tmpdir
833 #include "sql/rpl_trx_tracking.h"
834 #include "sql/sd_notify.h" // sd_notify_connect
835 #include "sql/session_tracker.h"
836 #include "sql/set_var.h"
837 #include "sql/sp_head.h" // init_sp_psi_keys
838 #include "sql/sql_audit.h" // mysql_audit_general
839 #include "sql/sql_base.h"
840 #include "sql/sql_callback.h" // MUSQL_CALLBACK
841 #include "sql/sql_class.h" // THD
842 #include "sql/sql_component.h"
843 #include "sql/sql_connect.h"
844 #include "sql/sql_error.h"
845 #include "sql/sql_initialize.h" // opt_initialize_insecure
846 #include "sql/sql_lex.h"
847 #include "sql/sql_list.h"
848 #include "sql/sql_locale.h" // MY_LOCALE
849 #include "sql/sql_manager.h" // start_handle_manager
850 #include "sql/sql_parse.h" // check_stack_overrun
851 #include "sql/sql_plugin.h" // opt_plugin_dir
852 #include "sql/sql_plugin_ref.h"
853 #include "sql/sql_reload.h" // handle_reload_request
854 #include "sql/sql_restart_server.h" // is_mysqld_managed
855 #include "sql/sql_servers.h"
856 #include "sql/sql_show.h"
857 #include "sql/sql_table.h" // build_table_filename
858 #include "sql/sql_udf.h"
859 #include "sql/ssl_acceptor_context_iterator.h"
860 #include "sql/ssl_acceptor_context_operator.h"
861 #include "sql/ssl_acceptor_context_status.h"
862 #include "sql/ssl_init_callback.h"
863 #include "sql/sys_vars.h" // fixup_enforce_gtid_consistency_...
864 #include "sql/sys_vars_shared.h" // intern_find_sys_var
865 #include "sql/table_cache.h" // table_cache_manager
866 #include "sql/tc_log.h" // tc_log
867 #include "sql/thd_raii.h"
868 #include "sql/thr_malloc.h"
869 #include "sql/threadpool.h"
870 #include "sql/transaction.h"
871 #include "sql/tztime.h" // Time_zone
872 #include "sql/udf_service_impl.h"
873 #include "sql/xa.h"
874 #include "sql/xa/transaction_cache.h" // xa::Transaction_cache
875 #include "sql_common.h" // mysql_client_plugin_init
876 #include "sql_string.h"
877 #include "storage/myisam/ha_myisam.h" // HA_RECOVER_OFF
878 #include "storage/perfschema/pfs_services.h"
879 #include "thr_lock.h"
880 #include "thr_mutex.h"
881 #include "typelib.h"
882 #include "violite.h"
883 #include "my_openssl_fips.h" // OPENSSL_ERROR_LENGTH, set_fips_mode
884
885 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
886 #include "storage/perfschema/pfs_server.h"
887 #endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
888
889 #ifdef _WIN32
890 #include "sql/conn_handler/named_pipe_connection.h"
891 #include "sql/conn_handler/shared_memory_connection.h"
892 #include "sql/named_pipe.h"
893 #endif
894
895 #ifdef HAVE_ARPA_INET_H
896 #include <arpa/inet.h>
897 #endif
898 #ifdef MY_MSCRT_DEBUG
899 #include <crtdbg.h>
900 #endif
901 #include <errno.h>
902 #include <fcntl.h>
903 #include <fenv.h>
904 #include <limits.h>
905 #ifdef HAVE_GRP_H
906 #include <grp.h>
907 #endif
908 #ifndef _WIN32
909 #include <netdb.h>
910 #endif
911 #ifdef HAVE_NETINET_IN_H
912 #include <netinet/in.h>
913 #endif
914 #include <signal.h>
915 #include <stdarg.h>
916 #include <stddef.h>
917 #include <stdio.h>
918 #include <stdlib.h>
919 #include <string.h>
920 #include <sys/types.h>
921 #ifdef HAVE_SYS_MMAN_H
922 #include <sys/mman.h>
923 #endif
924 #ifdef HAVE_SYS_PRCTL_H
925 #include <sys/prctl.h>
926 #endif
927 #ifdef HAVE_SYS_RESOURCE_H
928 #include <sys/resource.h>
929 #endif
930 #include <sys/stat.h>
931 #ifdef HAVE_UNISTD_H
932 #include <unistd.h>
933 #endif
934 #ifdef _WIN32
935 #include <crtdbg.h>
936 #include <process.h>
937 #endif
938 #include "unicode/putil.h" // u_setDataDirectory()
939 #include "unicode/uclean.h" // u_cleanup()
940
941 #ifdef WITH_WSREP
942 #include "sql/protocol_classic.h"
943 #include "sql_thd_internal_api.h"
944 #include "wsrep_mysqld.h"
945 #include "wsrep_sst.h"
946 #include "wsrep_thd.h"
947 #include "wsrep_utils.h"
948 #include "wsrep_var.h"
949 #endif /* WITH_WSREP */
950
951 #include <algorithm>
952 #include <atomic>
953 #include <functional>
954 #include <new>
955
956 #ifndef EMBEDDED_LIBRARY
957 #ifdef WITH_LOCK_ORDER
958 #include "sql/debug_lock_order.h"
959 #endif /* WITH_LOCK_ORDER */
960 #endif /* EMBEDDED_LIBRARY */
961
962 #ifndef EMBEDDED_LIBRARY
963 #include "srv_session.h"
964 #endif
965
966 #include <mysql/components/minimal_chassis.h>
967 #include <mysql/components/services/dynamic_loader_scheme_file.h>
968 #include <mysql/components/services/mysql_psi_system_service.h>
969 #include <mysql/components/services/mysql_rwlock_service.h>
970 #include <mysql/components/services/ongoing_transaction_query_service.h>
971 #include "sql/auth/dynamic_privileges_impl.h"
972 #include "sql/dd/dd.h" // dd::shutdown
973 #include "sql/dd/dd_kill_immunizer.h" // dd::DD_kill_immunizer
974 #include "sql/dd/dictionary.h" // dd::get_dictionary
975 #include "sql/dd/ndbinfo_schema/init.h" // dd::ndbinfo::init_schema_and_tables()
976 #include "sql/dd/performance_schema/init.h" // performance_schema::init
977 #include "sql/dd/upgrade/server.h" // dd::upgrade::upgrade_system_schemas
978 #include "sql/dd/upgrade_57/upgrade.h" // dd::upgrade_57::in_progress
979 #include "sql/server_component/component_sys_var_service_imp.h"
980 #include "sql/server_component/log_builtins_filter_imp.h"
981 #include "sql/server_component/log_builtins_imp.h"
982 #include "sql/server_component/mysql_server_keyring_lockable_imp.h"
983 #include "sql/server_component/persistent_dynamic_loader_imp.h"
984 #include "sql/srv_session.h"
985
986 using std::max;
987 using std::min;
988 using std::vector;
989
990 #define mysqld_charset &my_charset_latin1
991 #define mysqld_default_locale_name "en_US"
992
993 #ifdef HAVE_FPU_CONTROL_H
994 #include <fpu_control.h> // IWYU pragma: keep
995 #elif defined(__i386__)
996 #define fpu_control_t unsigned int
997 #define _FPU_EXTENDED 0x300
998 #define _FPU_DOUBLE 0x200
999 #if defined(__GNUC__)
1000 #define _FPU_GETCW(cw) asm volatile("fnstcw %0" : "=m"(*&cw))
1001 #define _FPU_SETCW(cw) asm volatile("fldcw %0" : : "m"(*&cw))
1002 #else
1003 #define _FPU_GETCW(cw) (cw = 0)
1004 #define _FPU_SETCW(cw)
1005 #endif
1006 #endif
1007 9759 inline void setup_fpu() {
1008 #ifdef HAVE_FEDISABLEEXCEPT
1009 9759 fedisableexcept(FE_ALL_EXCEPT);
1010 #endif
1011
1012 /* Set FPU rounding mode to "round-to-nearest" */
1013 9759 fesetround(FE_TONEAREST);
1014
1015 /*
1016 x86 (32-bit) requires FPU precision to be explicitly set to 64 bit
1017 (double precision) for portable results of floating point operations.
1018 However, there is no need to do so if compiler is using SSE2 for floating
1019 point, double values will be stored and processed in 64 bits anyway.
1020 */
1021 #if defined(__i386__) && !defined(__SSE2_MATH__)
1022 #if !defined(_WIN32)
1023 fpu_control_t cw;
1024 _FPU_GETCW(cw);
1025 cw = (cw & ~_FPU_EXTENDED) | _FPU_DOUBLE;
1026 _FPU_SETCW(cw);
1027 #endif /* _WIN32 && */
1028 #endif /* __i386__ */
1029 9759 }
1030
1031 extern "C" void handle_fatal_signal(int sig);
1032 void my_server_abort();
1033
1034 /* Constants */
1035
1036 #include "welcome_copyright_notice.h" // ORACLE_WELCOME_COPYRIGHT_NOTICE
1037
1038 const char *show_comp_option_name[] = {"YES", "NO", "DISABLED"};
1039
1040 static const char *tc_heuristic_recover_names[] = {"OFF", "COMMIT", "ROLLBACK",
1041 NullS};
1042 static TYPELIB tc_heuristic_recover_typelib = {
1043 array_elements(tc_heuristic_recover_names) - 1, "",
1044 tc_heuristic_recover_names, nullptr};
1045
1046 const char *first_keyword = "first", *binary_keyword = "BINARY";
1047 const char *my_localhost = "localhost";
1048
1049 bool opt_large_files = sizeof(my_off_t) > 4;
1050 static bool opt_autocommit; ///< for --autocommit command-line option
1051 static get_opt_arg_source source_autocommit;
1052
1053 /*
1054 Used with --help for detailed option
1055 */
1056 bool opt_help = false, opt_verbose = false, opt_validate_config = false;
1057
1058 arg_cmp_func Arg_comparator::comparator_matrix[5] = {
1059 &Arg_comparator::compare_string, // Compare strings
1060 &Arg_comparator::compare_real, // Compare float values
1061 &Arg_comparator::compare_int_signed, // Compare signed int values
1062 &Arg_comparator::compare_row, // Compare row values
1063 &Arg_comparator::compare_decimal}; // Compare decimal values
1064
1065 PSI_file_key key_file_binlog_cache;
1066 PSI_file_key key_file_binlog_index_cache;
1067
1068 #ifdef HAVE_PSI_INTERFACE
1069 static PSI_mutex_key key_LOCK_status;
1070 static PSI_mutex_key key_LOCK_manager;
1071 static PSI_mutex_key key_LOCK_crypt;
1072 static PSI_mutex_key key_LOCK_user_conn;
1073 static PSI_mutex_key key_LOCK_global_system_variables;
1074 static PSI_mutex_key key_LOCK_prepared_stmt_count;
1075 static PSI_mutex_key key_LOCK_replica_list;
1076 static PSI_mutex_key key_LOCK_sql_replica_skip_counter;
1077 static PSI_mutex_key key_LOCK_replica_net_timeout;
1078 static PSI_mutex_key key_LOCK_replica_trans_dep_tracker;
1079 static PSI_mutex_key key_LOCK_uuid_generator;
1080 static PSI_mutex_key key_LOCK_error_messages;
1081 static PSI_mutex_key key_LOCK_default_password_lifetime;
1082 static PSI_mutex_key key_LOCK_mandatory_roles;
1083 static PSI_mutex_key key_LOCK_password_history;
1084 static PSI_mutex_key key_LOCK_password_reuse_interval;
1085 static PSI_mutex_key key_LOCK_sql_rand;
1086 static PSI_mutex_key key_LOCK_log_throttle_qni;
1087 static PSI_mutex_key key_LOCK_reset_gtid_table;
1088 static PSI_mutex_key key_LOCK_compress_gtid_table;
1089 static PSI_mutex_key key_LOCK_collect_instance_log;
1090 static PSI_mutex_key key_BINLOG_LOCK_commit;
1091 static PSI_mutex_key key_BINLOG_LOCK_commit_queue;
1092 static PSI_mutex_key key_BINLOG_LOCK_done;
1093 static PSI_mutex_key key_BINLOG_LOCK_flush_queue;
1094 static PSI_mutex_key key_BINLOG_LOCK_index;
1095 static PSI_mutex_key key_BINLOG_LOCK_log;
1096 static PSI_mutex_key key_BINLOG_LOCK_binlog_end_pos;
1097 static PSI_mutex_key key_BINLOG_LOCK_sync;
1098 static PSI_mutex_key key_BINLOG_LOCK_sync_queue;
1099 static PSI_mutex_key key_BINLOG_LOCK_xids;
1100 static PSI_rwlock_key key_rwlock_global_sid_lock;
1101 PSI_rwlock_key key_rwlock_gtid_mode_lock;
1102 static PSI_rwlock_key key_rwlock_LOCK_system_variables_hash;
1103 static PSI_rwlock_key key_rwlock_LOCK_sys_init_connect;
1104 static PSI_rwlock_key key_rwlock_LOCK_sys_init_replica;
1105 static PSI_cond_key key_BINLOG_COND_done;
1106 static PSI_cond_key key_BINLOG_COND_flush_queue;
1107 static PSI_cond_key key_BINLOG_update_cond;
1108 static PSI_cond_key key_BINLOG_prep_xids_cond;
1109 static PSI_cond_key key_COND_manager;
1110 static PSI_cond_key key_COND_compress_gtid_table;
1111 static PSI_thread_key key_thread_signal_hand;
1112 static PSI_thread_key key_thread_main;
1113 static PSI_file_key key_file_casetest;
1114 static PSI_file_key key_file_pid;
1115 #if defined(_WIN32)
1116 static PSI_thread_key key_thread_handle_con_namedpipes;
1117 static PSI_thread_key key_thread_handle_con_sharedmem;
1118 static PSI_thread_key key_thread_handle_con_sockets;
1119 static PSI_mutex_key key_LOCK_handler_count;
1120 static PSI_cond_key key_COND_handler_count;
1121 static PSI_thread_key key_thread_handle_shutdown_restart;
1122 static PSI_rwlock_key key_rwlock_LOCK_named_pipe_full_access_group;
1123 #else
1124 static PSI_mutex_key key_LOCK_socket_listener_active;
1125 static PSI_cond_key key_COND_socket_listener_active;
1126 static PSI_mutex_key key_LOCK_start_signal_handler;
1127 static PSI_cond_key key_COND_start_signal_handler;
1128 #endif // _WIN32
1129 static PSI_mutex_key key_LOCK_server_started;
1130 static PSI_cond_key key_COND_server_started;
1131 static PSI_mutex_key key_LOCK_keyring_operations;
1132 static PSI_mutex_key key_LOCK_tls_ctx_options;
1133 static PSI_mutex_key key_LOCK_admin_tls_ctx_options;
1134 static PSI_mutex_key key_LOCK_rotate_binlog_master_key;
1135 static PSI_mutex_key key_LOCK_partial_revokes;
1136 static PSI_mutex_key key_LOCK_authentication_policy;
1137 static PSI_mutex_key key_LOCK_global_conn_mem_limit;
1138 #endif /* HAVE_PSI_INTERFACE */
1139
1140 /**
1141 Statement instrumentation key for replication.
1142 */
1143 #ifdef HAVE_PSI_STATEMENT_INTERFACE
1144 PSI_statement_info stmt_info_rpl;
1145 #endif
1146
1147 /* the default log output is log tables */
1148 static bool lower_case_table_names_used = false;
1149 #if !defined(_WIN32)
1150 static bool socket_listener_active = false;
1151 static int pipe_write_fd = -1;
1152 static bool opt_daemonize = false;
1153 #endif
1154 bool opt_debugging = false;
1155 static bool opt_external_locking = false, opt_console = false;
1156 static bool opt_short_log_format = false;
1157 static char *mysqld_user, *mysqld_chroot;
1158 static const char *default_character_set_name;
1159 static const char *character_set_filesystem_name;
1160 static const char *lc_messages;
1161 static const char *lc_time_names_name;
1162 char *my_bind_addr_str;
1163 char *my_admin_bind_addr_str;
1164 uint mysqld_admin_port;
1165 bool listen_admin_interface_in_separate_thread;
1166 char *my_proxy_protocol_networks;
1167 static const char *default_collation_name;
1168 const char *default_storage_engine;
1169 const char *default_tmp_storage_engine;
1170 ulonglong temptable_max_ram;
1171 ulonglong temptable_max_mmap;
1172 bool temptable_use_mmap;
1173 static char compiled_default_collation_name[] = MYSQL_DEFAULT_COLLATION_NAME;
1174 static bool binlog_format_used = false;
1175
1176 LEX_STRING opt_init_connect, opt_init_replica;
1177
1178 /* Global variables */
1179
1180 LEX_STRING opt_mandatory_roles;
1181 bool opt_mandatory_roles_cache = false;
1182 bool opt_always_activate_granted_roles = false;
1183 bool opt_bin_log;
1184 bool opt_general_log, opt_slow_log, opt_general_log_raw;
1185 ulonglong slow_query_log_always_write_time = 10000000;
1186 ulonglong log_output_options;
1187 bool opt_log_queries_not_using_indexes = false;
1188 ulong opt_log_throttle_queries_not_using_indexes = 0;
1189 bool opt_log_slow_extra = false;
1190 bool opt_disable_networking = false, opt_skip_show_db = false;
1191 bool opt_skip_name_resolve = false;
1192 bool opt_character_set_client_handshake = true;
1193 bool server_id_supplied = false;
1194 static bool opt_endinfo;
1195 bool using_udf_functions;
1196 bool locked_in_memory;
1197 bool opt_using_transactions;
1198 ulong opt_tc_log_size;
1199 std::atomic<int32> connection_events_loop_aborted_flag;
1200 static std::atomic<enum_server_operational_state> server_operational_state{
1201 SERVER_BOOTING};
1202 char *opt_log_error_suppression_list;
1203 char *opt_log_error_services;
1204 char *opt_keyring_migration_user = nullptr;
1205 char *opt_keyring_migration_host = nullptr;
1206 char *opt_keyring_migration_password = nullptr;
1207 char *opt_keyring_migration_socket = nullptr;
1208 char *opt_keyring_migration_source = nullptr;
1209 char *opt_keyring_migration_destination = nullptr;
1210 ulong opt_keyring_migration_port = 0;
1211 bool migrate_connect_options = false;
1212 uint host_cache_size;
1213 ulong log_error_verbosity = 3; // have a non-zero value during early start-up
1214 bool opt_keyring_migration_to_component = false;
1215 bool opt_libcoredumper, opt_corefile = 0;
1216 bool opt_persist_sensitive_variables_in_plaintext{true};
1217
1218 #if defined(_WIN32)
1219 /*
1220 Thread handle of shutdown event handler thread.
1221 It is used as argument during thread join.
1222 */
1223 my_thread_handle shutdown_restart_thr_handle;
1224
1225 ulong slow_start_timeout;
1226 bool opt_no_monitor = false;
1227 #endif
1228
1229 bool opt_no_dd_upgrade = false;
1230 long opt_upgrade_mode = UPGRADE_AUTO;
1231 bool opt_initialize = false;
1232 bool dd_init_failed_during_upgrade = false;
1233 bool opt_skip_replica_start = false; ///< If set, slave is not autostarted
1234 bool opt_enable_named_pipe = false;
1235 bool opt_local_infile, opt_replica_compressed_protocol;
1236 bool opt_safe_user_create = false;
1237 bool opt_show_replica_auth_info;
1238 bool opt_log_replica_updates = false;
1239 char *opt_replica_skip_errors;
1240 bool opt_replica_allow_batching = true;
1241
1242 /**
1243 compatibility option:
1244 - index usage hints (USE INDEX without a FOR clause) behave as in 5.0
1245 */
1246 bool old_mode;
1247
1248 /*
1249 Legacy global handlerton. These will be removed (please do not add more).
1250 */
1251 handlerton *heap_hton;
1252 handlerton *temptable_hton;
1253 handlerton *myisam_hton;
1254 handlerton *innodb_hton;
1255
1256 char *opt_disabled_storage_engines;
1257 uint opt_server_id_bits = 0;
1258 ulong opt_server_id_mask = 0;
1259 bool read_only = false, opt_readonly = false;
1260 bool super_read_only = false, opt_super_readonly = false;
1261 bool opt_require_secure_transport = false;
1262 bool relay_log_purge;
1263 bool relay_log_recovery;
1264 bool opt_allow_suspicious_udfs;
1265 const char *opt_secure_file_priv;
1266 const char *opt_secure_log_path;
1267 bool opt_log_slow_admin_statements = false;
1268 bool opt_log_slow_replica_statements = false;
1269 bool lower_case_file_system = false;
1270 bool opt_large_pages = false;
1271 bool opt_super_large_pages = false;
1272 bool opt_myisam_use_mmap = false;
1273 std::atomic<bool> offline_mode;
1274 uint opt_large_page_size = 0;
1275 uint default_password_lifetime = 0;
1276 ulonglong opt_slow_query_log_use_global_control = 0;
1277 ulong opt_slow_query_log_rate_type = 0;
1278 bool password_require_current = false;
1279 std::atomic<bool> partial_revokes;
1280 bool opt_partial_revokes; // Initialized through Sys_var
1281
1282 mysql_mutex_t LOCK_default_password_lifetime;
1283 mysql_mutex_t LOCK_mandatory_roles;
1284 mysql_mutex_t LOCK_password_history;
1285 mysql_mutex_t LOCK_password_reuse_interval;
1286 mysql_mutex_t LOCK_tls_ctx_options;
1287 mysql_mutex_t LOCK_admin_tls_ctx_options;
1288 mysql_mutex_t LOCK_partial_revokes;
1289
1290 #if defined(ENABLED_DEBUG_SYNC)
1291 MYSQL_PLUGIN_IMPORT uint opt_debug_sync_timeout = 0;
1292 #endif /* defined(ENABLED_DEBUG_SYNC) */
1293 bool opt_old_style_user_limits = false, trust_function_creators = false;
1294 bool check_proxy_users = false, mysql_native_password_proxy_users = false,
1295 sha256_password_proxy_users = false;
1296 bool opt_userstat = false;
1297 bool opt_thread_statistics = false;
1298 /*
1299 True if there is at least one per-hour limit for some user, so we should
1300 check them before each query (and possibly reset counters when hour is
1301 changed). False otherwise.
1302 */
1303 volatile bool mqh_used = false;
1304 bool opt_noacl = false;
1305 bool sp_automatic_privileges = true;
1306
1307 int32_t opt_regexp_time_limit;
1308 int32_t opt_regexp_stack_limit;
1309
1310 /** True, if restarted from a cloned database. This information
1311 is needed by GR to set some configurations right after clone. */
1312 bool clone_startup = false;
1313
1314 /** True, if clone recovery has failed. For managed server we
1315 restart server again with old database files. */
1316 bool clone_recovery_error = false;
1317
1318 ulong binlog_row_event_max_size;
1319 ulong binlog_checksum_options;
1320 ulong binlog_row_metadata;
1321 bool opt_source_verify_checksum = false;
1322 bool opt_replica_sql_verify_checksum = true;
1323 const char *binlog_format_names[] = {"MIXED", "STATEMENT", "ROW", NullS};
1324 bool binlog_gtid_simple_recovery;
1325 ulong binlog_error_action;
1326 const char *binlog_error_action_list[] = {"IGNORE_ERROR", "ABORT_SERVER",
1327 NullS};
1328 bool opt_binlog_skip_flush_commands = false;
1329 uint32 gtid_executed_compression_period = 0;
1330 bool opt_log_unsafe_statements;
1331
1332 const char *timestamp_type_names[] = {"UTC", "SYSTEM", NullS};
1333 ulong opt_log_timestamps;
1334 uint mysqld_port, test_flags = 0, select_errors, ha_open_options;
1335 uint mysqld_port_timeout;
1336 ulong delay_key_write_options;
1337 uint protocol_version;
1338 uint lower_case_table_names;
1339 long tc_heuristic_recover;
1340 ulong back_log, connect_timeout, server_id;
1341 ulong table_cache_size;
1342 ulong table_cache_instances;
1343 ulong table_cache_size_per_instance;
1344 ulong schema_def_size;
1345 ulong stored_program_def_size;
1346 ulong table_def_size;
1347 ulong tablespace_def_size;
1348 ulong what_to_log;
1349 ulong slow_launch_time;
1350 std::atomic<int32> atomic_replica_open_temp_tables{0};
1351 ulong open_files_limit, max_binlog_size, max_relay_log_size;
1352 ulong slave_trans_retries;
1353 uint replica_net_timeout;
1354 ulong replica_exec_mode_options;
1355 ulonglong replica_type_conversions_options;
1356 ulong opt_mts_replica_parallel_workers;
1357 ulonglong opt_mts_pending_jobs_size_max;
1358 ulonglong slave_rows_search_algorithms_options;
1359 bool opt_replica_preserve_commit_order;
1360 #ifndef NDEBUG
1361 uint replica_rows_last_search_algorithm_used;
1362 #endif
1363 ulong mts_parallel_option;
1364 ulong binlog_cache_size = 0;
1365 ulonglong max_binlog_cache_size = 0;
1366 ulong net_buffer_shrink_interval = 0;
1367 ulong replica_max_allowed_packet = 0;
1368 ulong binlog_stmt_cache_size = 0;
1369 int32 opt_binlog_max_flush_queue_time = 0;
1370 long opt_binlog_group_commit_sync_delay = 0;
1371 ulong opt_binlog_group_commit_sync_no_delay_count = 0;
1372 ulonglong max_binlog_stmt_cache_size = 0;
1373 ulong refresh_version; /* Increments on each reload */
1374 std::atomic<query_id_t> atomic_global_query_id{1};
1375 ulong aborted_threads;
1376 ulong delayed_insert_timeout, delayed_insert_limit, delayed_queue_size;
1377 ulong delayed_insert_threads, delayed_insert_writes, delayed_rows_in_use;
1378 ulong delayed_insert_errors, flush_time;
1379 ulong specialflag = 0;
1380 ulong binlog_cache_use = 0, binlog_cache_disk_use = 0;
1381 ulong binlog_stmt_cache_use = 0, binlog_stmt_cache_disk_use = 0;
1382 ulong max_connections, max_connect_errors;
1383 ulong rpl_stop_replica_timeout = LONG_TIMEOUT;
1384 bool log_bin_use_v1_row_events = false;
1385 bool thread_cache_size_specified = false;
1386 bool host_cache_size_specified = false;
1387 bool table_definition_cache_specified = false;
1388 ulong locked_account_connection_count = 0;
1389
1390 ulonglong denied_connections = 0;
1391 ulonglong global_conn_mem_limit = 0;
1392 ulonglong global_conn_mem_counter = 0;
1393
1394 /**
1395 This variable holds handle to the object that's responsible
1396 for loading/unloading components from manifest file
1397 */
1398 Deployed_components *g_deployed_components = nullptr;
1399
1400 /**
1401 Limit of the total number of prepared statements in the server.
1402 Is necessary to protect the server against out-of-memory attacks.
1403 */
1404 ulong max_prepared_stmt_count;
1405 /**
1406 Current total number of prepared statements in the server. This number
1407 is exact, and therefore may not be equal to the difference between
1408 `com_stmt_prepare' and `com_stmt_close' (global status variables), as
1409 the latter ones account for all registered attempts to prepare
1410 a statement (including unsuccessful ones). Prepared statements are
1411 currently connection-local: if the same SQL query text is prepared in
1412 two different connections, this counts as two distinct prepared
1413 statements.
1414 */
1415 ulong prepared_stmt_count = 0;
1416 ulong current_pid;
1417 uint sync_binlog_period = 0, sync_relaylog_period = 0,
1418 sync_relayloginfo_period = 0, sync_masterinfo_period = 0,
1419 opt_mta_checkpoint_period, opt_mta_checkpoint_group;
1420 ulong expire_logs_days = 0;
1421 ulong binlog_expire_logs_seconds = 0;
1422 bool opt_binlog_expire_logs_auto_purge{true};
1423 /**
1424 Soft upper limit for number of sp_head objects that can be stored
1425 in the sp_cache for one connection.
1426 */
1427 ulong stored_program_cache_size = 0;
1428 /**
1429 Compatibility option to prevent auto upgrade of old temporals
1430 during certain ALTER TABLE operations.
1431 */
1432 bool avoid_temporal_upgrade;
1433
1434 bool persisted_globals_load = true;
1435
1436 bool opt_keyring_operations = true;
1437
1438 bool opt_table_encryption_privilege_check = false;
1439
1440 const double log_10[] = {
1441 1e000, 1e001, 1e002, 1e003, 1e004, 1e005, 1e006, 1e007, 1e008, 1e009, 1e010,
1442 1e011, 1e012, 1e013, 1e014, 1e015, 1e016, 1e017, 1e018, 1e019, 1e020, 1e021,
1443 1e022, 1e023, 1e024, 1e025, 1e026, 1e027, 1e028, 1e029, 1e030, 1e031, 1e032,
1444 1e033, 1e034, 1e035, 1e036, 1e037, 1e038, 1e039, 1e040, 1e041, 1e042, 1e043,
1445 1e044, 1e045, 1e046, 1e047, 1e048, 1e049, 1e050, 1e051, 1e052, 1e053, 1e054,
1446 1e055, 1e056, 1e057, 1e058, 1e059, 1e060, 1e061, 1e062, 1e063, 1e064, 1e065,
1447 1e066, 1e067, 1e068, 1e069, 1e070, 1e071, 1e072, 1e073, 1e074, 1e075, 1e076,
1448 1e077, 1e078, 1e079, 1e080, 1e081, 1e082, 1e083, 1e084, 1e085, 1e086, 1e087,
1449 1e088, 1e089, 1e090, 1e091, 1e092, 1e093, 1e094, 1e095, 1e096, 1e097, 1e098,
1450 1e099, 1e100, 1e101, 1e102, 1e103, 1e104, 1e105, 1e106, 1e107, 1e108, 1e109,
1451 1e110, 1e111, 1e112, 1e113, 1e114, 1e115, 1e116, 1e117, 1e118, 1e119, 1e120,
1452 1e121, 1e122, 1e123, 1e124, 1e125, 1e126, 1e127, 1e128, 1e129, 1e130, 1e131,
1453 1e132, 1e133, 1e134, 1e135, 1e136, 1e137, 1e138, 1e139, 1e140, 1e141, 1e142,
1454 1e143, 1e144, 1e145, 1e146, 1e147, 1e148, 1e149, 1e150, 1e151, 1e152, 1e153,
1455 1e154, 1e155, 1e156, 1e157, 1e158, 1e159, 1e160, 1e161, 1e162, 1e163, 1e164,
1456 1e165, 1e166, 1e167, 1e168, 1e169, 1e170, 1e171, 1e172, 1e173, 1e174, 1e175,
1457 1e176, 1e177, 1e178, 1e179, 1e180, 1e181, 1e182, 1e183, 1e184, 1e185, 1e186,
1458 1e187, 1e188, 1e189, 1e190, 1e191, 1e192, 1e193, 1e194, 1e195, 1e196, 1e197,
1459 1e198, 1e199, 1e200, 1e201, 1e202, 1e203, 1e204, 1e205, 1e206, 1e207, 1e208,
1460 1e209, 1e210, 1e211, 1e212, 1e213, 1e214, 1e215, 1e216, 1e217, 1e218, 1e219,
1461 1e220, 1e221, 1e222, 1e223, 1e224, 1e225, 1e226, 1e227, 1e228, 1e229, 1e230,
1462 1e231, 1e232, 1e233, 1e234, 1e235, 1e236, 1e237, 1e238, 1e239, 1e240, 1e241,
1463 1e242, 1e243, 1e244, 1e245, 1e246, 1e247, 1e248, 1e249, 1e250, 1e251, 1e252,
1464 1e253, 1e254, 1e255, 1e256, 1e257, 1e258, 1e259, 1e260, 1e261, 1e262, 1e263,
1465 1e264, 1e265, 1e266, 1e267, 1e268, 1e269, 1e270, 1e271, 1e272, 1e273, 1e274,
1466 1e275, 1e276, 1e277, 1e278, 1e279, 1e280, 1e281, 1e282, 1e283, 1e284, 1e285,
1467 1e286, 1e287, 1e288, 1e289, 1e290, 1e291, 1e292, 1e293, 1e294, 1e295, 1e296,
1468 1e297, 1e298, 1e299, 1e300, 1e301, 1e302, 1e303, 1e304, 1e305, 1e306, 1e307,
1469 1e308};
1470
1471 /* Index extension. */
1472 const int index_ext_length = 6;
1473 const char *index_ext = ".index";
1474 const int relay_ext_length = 10;
1475 const char *relay_ext = "-relay-bin";
1476 /* True if --log-bin option is used. */
1477 bool log_bin_supplied = false;
1478
1479 time_t server_start_time, flush_status_time;
1480
1481 char server_uuid[UUID_LENGTH + 1];
1482 const char *server_uuid_ptr;
1483 char mysql_home[FN_REFLEN], pidfile_name[FN_REFLEN];
1484 char system_time_zone_dst_on[30], system_time_zone_dst_off[30];
1485 char default_logfile_name[FN_REFLEN];
1486 char default_binlogfile_name[FN_REFLEN];
1487 char default_binlog_index_name[FN_REFLEN + index_ext_length];
1488 char default_relaylogfile_name[FN_REFLEN + relay_ext_length];
1489 char default_relaylog_index_name[FN_REFLEN + relay_ext_length +
1490 index_ext_length];
1491 char *default_tz_name;
1492 static char errorlog_filename_buff[FN_REFLEN];
1493 const char *log_error_dest;
1494 const char *my_share_dir[FN_REFLEN];
1495 char glob_hostname[HOSTNAME_LENGTH + 1];
1496 char mysql_real_data_home[FN_REFLEN], lc_messages_dir[FN_REFLEN],
1497 reg_ext[FN_EXTLEN], mysql_charsets_dir[FN_REFLEN], *opt_init_file;
1498 const char *opt_tc_log_file;
1499 char *lc_messages_dir_ptr;
1500 char mysql_unpacked_real_data_home[FN_REFLEN];
1501 size_t mysql_unpacked_real_data_home_len;
1502 size_t mysql_data_home_len = 1;
1503 uint reg_ext_length;
1504 char logname_path[FN_REFLEN];
1505 char slow_logname_path[FN_REFLEN];
1506 char secure_file_real_path[FN_REFLEN];
1507 char secure_log_real_path[FN_REFLEN];
1508 Time_zone *default_tz;
1509 char *mysql_data_home = const_cast<char *>(".");
1510 const char *mysql_real_data_home_ptr = mysql_real_data_home;
1511 char *opt_protocol_compression_algorithms;
1512 char server_version[SERVER_VERSION_LENGTH];
1513 char server_version_suffix[SERVER_VERSION_LENGTH];
1514 const char *mysqld_unix_port;
1515 char *opt_mysql_tmpdir;
1516
1517 char *opt_authentication_policy;
1518 std::vector<std::string> authentication_policy_list;
1519 /*
1520 keep track of plugin_ref until plugins used in opt_authentication_policy
1521 are properly validated and updated. This will ensure that plugin is not
1522 unloaded in between check() and update() of authentication_policy variable
1523 */
1524 std::vector<plugin_ref> authentication_policy_plugin_ref;
1525
1526 bool encrypt_tmp_files;
1527
1528 ulonglong tf_sequence_table_max_upper_bound = 0;
1529
1530 /** name of reference on left expression in rewritten IN subquery */
1531 const char *in_left_expr_name = "<left expr>";
1532
1533 my_decimal decimal_zero;
1534 /** Number of connection errors from internal server errors. */
1535 ulong connection_errors_internal = 0;
1536 /** Number of errors when reading the peer address. */
1537 ulong connection_errors_peer_addr = 0;
1538
1539 /* classes for comparison parsing/processing */
1540 Eq_creator eq_creator;
1541 Ne_creator ne_creator;
1542 Equal_creator equal_creator;
1543 Gt_creator gt_creator;
1544 Lt_creator lt_creator;
1545 Ge_creator ge_creator;
1546 Le_creator le_creator;
1547
1548 Rpl_global_filter rpl_global_filter;
1549 Rpl_filter *binlog_filter;
1550 Rpl_acf_configuration_handler *rpl_acf_configuration_handler = nullptr;
1551 Source_IO_monitor *rpl_source_io_monitor = nullptr;
1552 Udf_load_service udf_load_service;
1553
1554 struct System_variables global_system_variables;
1555 struct System_variables max_system_variables;
1556 struct System_status_var global_status_var;
1557
1558 MY_TMPDIR mysql_tmpdir_list;
1559
1560 CHARSET_INFO *system_charset_info, *files_charset_info;
1561 CHARSET_INFO *national_charset_info, *table_alias_charset;
1562 CHARSET_INFO *character_set_filesystem;
1563
1564 MY_LOCALE *my_default_lc_messages;
1565 MY_LOCALE *my_default_lc_time_names;
1566
1567 SHOW_COMP_OPTION have_symlink, have_dlopen, have_query_cache;
1568 SHOW_COMP_OPTION have_geometry, have_rtree_keys;
1569 SHOW_COMP_OPTION have_compress;
1570 SHOW_COMP_OPTION have_profiling;
1571 SHOW_COMP_OPTION have_statement_timeout = SHOW_OPTION_DISABLED;
1572 SHOW_COMP_OPTION have_backup_locks;
1573 SHOW_COMP_OPTION have_backup_safe_binlog_info;
1574 SHOW_COMP_OPTION have_snapshot_cloning;
1575
1576 char *enforce_storage_engine = nullptr;
1577
1578 char *utility_user = nullptr;
1579 char *utility_user_password = nullptr;
1580 char *utility_user_schema_access = nullptr;
1581
1582 char *opt_libcoredumper_path = NULL;
1583 /* Plucking this from sql/sql_acl.cc for an array of privilege names */
1584 extern TYPELIB utility_user_privileges_typelib;
1585 ulonglong utility_user_privileges = 0;
1586 char *utility_user_dynamic_privileges = nullptr;
1587
1588 /* Thread specific variables */
1589
1590 thread_local MEM_ROOT **THR_MALLOC = nullptr;
1591
1592 mysql_mutex_t LOCK_status, LOCK_uuid_generator, LOCK_crypt,
1593 LOCK_global_system_variables, LOCK_user_conn, LOCK_error_messages;
1594 mysql_mutex_t LOCK_sql_rand;
1595
1596 mysql_mutex_t LOCK_global_user_client_stats, LOCK_global_table_stats,
1597 LOCK_global_index_stats;
1598 /**
1599 The below lock protects access to two global server variables:
1600 max_prepared_stmt_count and prepared_stmt_count. These variables
1601 set the limit and hold the current total number of prepared statements
1602 in the server, respectively. As PREPARE/DEALLOCATE rate in a loaded
1603 server may be fairly high, we need a dedicated lock.
1604 */
1605 mysql_mutex_t LOCK_prepared_stmt_count;
1606
1607 /**
1608 Protects slave_list in rpl_source.cc; the list of currently running
1609 dump threads with metadata for the replica.
1610 */
1611 mysql_mutex_t LOCK_replica_list;
1612 /*
1613 The below two locks are introduced as guards (second mutex) for
1614 the global variables sql_replica_skip_counter and replica_net_timeout
1615 respectively. See fix_slave_skip_counter/fix_replica_net_timeout
1616 for more details
1617 */
1618 mysql_mutex_t LOCK_sql_replica_skip_counter;
1619 mysql_mutex_t LOCK_replica_net_timeout;
1620 mysql_mutex_t LOCK_replica_trans_dep_tracker;
1621 mysql_mutex_t LOCK_log_throttle_qni;
1622 mysql_rwlock_t LOCK_sys_init_connect, LOCK_sys_init_replica;
1623 mysql_rwlock_t LOCK_system_variables_hash;
1624 my_thread_handle signal_thread_id;
1625 sigset_t mysqld_signal_mask;
1626 my_thread_attr_t connection_attrib;
1627 mysql_mutex_t LOCK_server_started;
1628 mysql_cond_t COND_server_started;
1629 mysql_mutex_t LOCK_reset_gtid_table;
1630 mysql_mutex_t LOCK_compress_gtid_table;
1631 mysql_cond_t COND_compress_gtid_table;
1632 mysql_mutex_t LOCK_collect_instance_log;
1633 #if !defined(_WIN32)
1634 mysql_mutex_t LOCK_socket_listener_active;
1635 mysql_cond_t COND_socket_listener_active;
1636 mysql_mutex_t LOCK_start_signal_handler;
1637 mysql_cond_t COND_start_signal_handler;
1638 #endif
1639 mysql_rwlock_t LOCK_consistent_snapshot;
1640
1641 #ifdef WITH_WSREP
1642 mysql_mutex_t LOCK_wsrep_ready;
1643 mysql_cond_t COND_wsrep_ready;
1644 mysql_mutex_t LOCK_wsrep_sst;
1645 mysql_cond_t COND_wsrep_sst;
1646 mysql_mutex_t LOCK_wsrep_sst_init;
1647 mysql_cond_t COND_wsrep_sst_init;
1648 mysql_mutex_t LOCK_wsrep_replaying;
1649 mysql_cond_t COND_wsrep_replaying;
1650 mysql_mutex_t LOCK_wsrep_slave_threads;
1651 mysql_cond_t COND_wsrep_slave_threads;
1652 mysql_mutex_t LOCK_wsrep_cluster_config;
1653 mysql_mutex_t LOCK_wsrep_desync;
1654 mysql_mutex_t LOCK_wsrep_group_commit;
1655 mysql_cond_t COND_wsrep_group_commit;
1656 mysql_mutex_t LOCK_wsrep_SR_pool;
1657 mysql_mutex_t LOCK_wsrep_SR_store;
1658 mysql_mutex_t LOCK_wsrep_alter_tablespace;
1659
1660 // Track replaying thread handler(s).
1661 int wsrep_replaying = 0;
1662
1663 // currently running wsrep threads
1664 std::atomic<ulong> wsrep_running_threads{0};
1665
1666 /*
1667 If server is being aborted avoid persisting SE checkpoint.
1668 abort suggest error situation with introduction of encrypted tablespace
1669 if abort originate from tablespace error then persist of SE checkpoint
1670 to tablespace will not work.
1671 */
1672 bool wsrep_unireg_abort = false;
1673
1674 static void wsrep_close_threads(THD *thd);
1675 #endif /* WITH_WSREP */
1676
1677 /*
1678 The below lock protects access to global server variable
1679 keyring_operations.
1680 */
1681 mysql_mutex_t LOCK_keyring_operations;
1682 /*
1683 The below lock protects to execute commands 'ALTER INSTANCE ROTATE BINLOG
1684 MASTER KEY' and 'SET @@GLOBAL.binlog_encryption=ON/OFF' in parallel.
1685 */
1686 mysql_mutex_t LOCK_rotate_binlog_master_key;
1687
1688 /*
1689 The below lock protects to execute commands 'CREATE/ALTER USER' and
1690 'SET @@GLOBAL.authentication_policy...' in parallel.
1691 */
1692 mysql_mutex_t LOCK_authentication_policy;
1693
1694 mysql_mutex_t LOCK_global_conn_mem_limit;
1695
1696 bool mysqld_server_started = false;
1697 /**
1698 Set to true to signal at startup if the process must die.
1699
1700 Needed because kill_mysql() will not do anything before
1701 the server is fully initialized. Thus it now just sets this
1702 flag to on and exits. And then mysqld_main() will check if
1703 the flag is on at the right place and exit the process if it
1704 is.
1705 */
1706 static bool mysqld_process_must_end_at_startup = false;
1707
1708 /* replication parameters, if master_host is not NULL, we are a slave */
1709 uint report_port = 0;
1710 ulong master_retry_count = 0;
1711 const char *master_info_file;
1712 const char *relay_log_info_file;
1713 char *report_user, *report_password, *report_host;
1714 char *opt_relay_logname = nullptr, *opt_relaylog_index_name = nullptr;
1715 /*
1716 True if the --relay-log-index is set by users from
1717 config file or command line.
1718 */
1719 bool opt_relaylog_index_name_supplied = false;
1720 /*
1721 True if the --relay-log is set by users from
1722 config file or command line.
1723 */
1724 bool opt_relay_logname_supplied = false;
1725 /*
1726 True if --log-replica-updates option is set explicitly
1727 on command line or configuration file.
1728 */
1729 bool log_replica_updates_supplied = false;
1730
1731 /*
1732 True if --replica-preserve-commit-order-supplied option is set explicitly
1733 on command line or configuration file.
1734 */
1735 bool replica_preserve_commit_order_supplied = false;
1736 char *opt_general_logname, *opt_slow_logname, *opt_bin_logname;
1737
1738 /*
1739 True if expire_logs_days and binlog_expire_logs_seconds are set
1740 explicitly.
1741 */
1742 bool expire_logs_days_supplied = false;
1743 bool binlog_expire_logs_seconds_supplied = false;
1744 /* Static variables */
1745
1746 static bool opt_myisam_log;
1747 static int cleanup_done;
1748 static ulong opt_specialflag;
1749 char *opt_binlog_index_name;
1750 char *mysql_home_ptr, *pidfile_name_ptr;
1751 char *default_auth_plugin;
1752 /**
1753 Memory for allocating command line arguments, after load_defaults().
1754 */
1755 static MEM_ROOT argv_alloc{PSI_NOT_INSTRUMENTED, 512};
1756 /** Remaining command line arguments (count), filtered by handle_options().*/
1757 static int remaining_argc;
1758 /** Remaining command line arguments (arguments), filtered by
1759 * handle_options().*/
1760 static char **remaining_argv;
1761
1762 /**
1763 Holds the "original" (i.e. as on startup) set of arguments.
1764
1765 The argument processing goes as follows:
1766 1. At startup the "original" set of arguments is shallow-copied into
1767 the read only list @ref orig_argv.
1768 2. The config file arguments are read from the config files (.cnf and
1769 persisted read-only) and are appended as command line arguments.
1770 In the process the argv is deep copied because of the expansion
1771 3. The result from 2 is set into @ref remaining_argv / @ref remaining_argc.
1772 4. Then remaining_argv is fed into various consumers:
1773 - the server compiled in set of arguments
1774 - the early plugins
1775 - the rest of the plugins
1776 - the error log
1777 - the components from the persisted dynamic loader init.
1778 All of the above "take away" the values they match from the extended
1779 command line set. And vary the values of @ref my_getopt_skip_unknown
1780 according to their needs (mostly keep it set).
1781 As a result, when the server is done booting up the things that remain
1782 in remaining_argv become less and less.
1783 5. When the bootstrap process is done a check is run:
1784 my_getopt_skip_unknown is set to off and the argument parser is called
1785 on remaining_argv with an empty set of argument definitions.
1786 This ensures that all of the remaining argument values in remaining_argv
1787 are either marked as "loose" (i.e. optional) or are "consumed" by prior
1788 argument list processings.
1789 The side effect of this is that all --loose arguments are also consumed
1790 out of remaining_argv.
1791 6. A check is made if the remaining_argv is an empty list. If not the server
1792 exits.
1793 7. At this point the server is marked as successfully started.
1794 8. Subsequent argument processings happen when e.g. a plugin is loaded via
1795 @ref mysql_install_plugin or a component registers system variables via
1796 @ref mysql_component_sys_variable_imp::register_variable. However, since
1797 remaining_argv is empty these need to run over the orig_argc/orig_argv.
1798 But argument value assignment would normally "eat" out the values found.
1799 This would mean that the orig_argv array will get shortened and if you
1800 load the same plugin twice for example its system variables will not have
1801 the values supplied the second time they start.
1802 Thus once the server is started (@ref mysqld_server_started is on) any
1803 argument value parsing should happen over a *copy* of orig_argc/orig_argv
1804 that should subsequently be discarded.
1805 @ref remaining_argv should not be consulted anymore at this point.
1806 */
1807 int orig_argc;
1808 char **orig_argv;
1809 namespace {
1810 FILE *nstdout = nullptr;
1811 char my_progpath[FN_REFLEN];
1812 const char *my_orig_progname = nullptr;
1813
1814 /**
1815 This variable holds the exit value of the signal handler thread.
1816 */
1817 std::atomic<int> signal_hand_thr_exit_code(MYSQLD_SUCCESS_EXIT);
1818
1819 /**
1820 Inspects the program name in argv[0] and substitutes the full path
1821 of the executable.
1822
1823 @param argv argument vector (array) for executable.
1824 */
1825 10136 void substitute_progpath(char **argv) {
1826
2/2
✓ Branch 0 taken 10134 times.
✓ Branch 1 taken 2 times.
10136 if (test_if_hard_path(argv[0])) return;
1827
1828 #if defined(_WIN32)
1829 if (GetModuleFileName(NULL, my_progpath, sizeof(my_progpath))) {
1830 my_orig_progname = argv[0];
1831 argv[0] = my_progpath;
1832 }
1833 #else
1834 /* If the path has a directory component, use my_realpath()
1835 (implicitly relative to cwd) */
1836
4/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
3 if (strchr(argv[0], FN_LIBCHAR) != nullptr &&
1837
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 !my_realpath(my_progpath, argv[0], MYF(0))) {
1838 1 my_orig_progname = argv[0];
1839 1 argv[0] = my_progpath;
1840 1 return;
1841 }
1842
1843 // my_realpath() cannot resolve it, it must be a bare executable
1844 // name in path
1845
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert(strchr(argv[0], FN_LIBCHAR) == nullptr);
1846
1847 1 const char *spbegin = getenv("PATH");
1848
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (spbegin == nullptr) spbegin = "";
1849 1 const char *spend = spbegin + strlen(spbegin);
1850
1851 while (true) {
1852
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 const char *colonend = std::find(spbegin, spend, ':');
1853
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::string cand{spbegin, colonend};
1854 1 spbegin = colonend + 1;
1855
1856
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 cand.append(1, '/');
1857
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 cand.append(argv[0]);
1858
1859
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (my_access(cand.c_str(), X_OK) == 0) {
1860
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 if (my_realpath(my_progpath, cand.c_str(), MYF(0))) {
1861 // Fallback to raw cand
1862 assert(cand.length() < FN_REFLEN);
1863 std::copy(cand.begin(), cand.end(), my_progpath);
1864 my_progpath[cand.length()] = '\0';
1865 }
1866 1 my_orig_progname = argv[0];
1867 1 argv[0] = my_progpath;
1868 1 break;
1869 }
1870 if (colonend == spend) {
1871 assert(false);
1872 break;
1873 }
1874
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 } // while (true)
1875 #endif // defined(_WIN32)
1876
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (my_orig_progname == nullptr) {
1877 LogErr(WARNING_LEVEL, ER_FAILED_TO_GET_ABSOLUTE_PATH, argv[0]);
1878 }
1879 }
1880 } // namespace
1881
1882 static Connection_acceptor<Mysqld_socket_listener> *mysqld_socket_acceptor =
1883 nullptr;
1884 #ifdef _WIN32
1885 static Named_pipe_listener *named_pipe_listener = NULL;
1886 Connection_acceptor<Named_pipe_listener> *named_pipe_acceptor = NULL;
1887 Connection_acceptor<Shared_mem_listener> *shared_mem_acceptor = NULL;
1888 mysql_rwlock_t LOCK_named_pipe_full_access_group;
1889 char *named_pipe_full_access_group;
1890 #endif
1891
1892 Checkable_rwlock *global_sid_lock = nullptr;
1893 Sid_map *global_sid_map = nullptr;
1894 Gtid_state *gtid_state = nullptr;
1895 Gtid_table_persistor *gtid_table_persistor = nullptr;
1896
1897 /* cache for persisted variables */
1898 static Persisted_variables_cache persisted_variables_cache;
1899
1900 12 void persisted_variables_refresh_keyring_support() {
1901 12 persisted_variables_cache.keyring_support_available();
1902 12 }
1903
1904 11 void set_remaining_args(int argc, char **argv) {
1905 11 remaining_argc = argc;
1906 11 remaining_argv = argv;
1907 11 }
1908
1909 141 int *get_remaining_argc() { return &remaining_argc; }
1910
1911 141 char ***get_remaining_argv() { return &remaining_argv; }
1912
1913 /*
1914 Multiple threads of execution use the random state maintained in global
1915 sql_rand to generate random numbers. sql_rnd_with_mutex use mutex
1916 LOCK_sql_rand to protect sql_rand across multiple instantiations that use
1917 sql_rand to generate random numbers.
1918 */
1919 1172046 ulong sql_rnd_with_mutex() {
1920 1172046 mysql_mutex_lock(&LOCK_sql_rand);
1921 ulong tmp =
1922 1173152 (ulong)(my_rnd(&sql_rand) * 0xffffffff); /* make all bits random */
1923 1173152 mysql_mutex_unlock(&LOCK_sql_rand);
1924 1173152 return tmp;
1925 }
1926
1927 338859 struct System_status_var *get_thd_status_var(THD *thd, bool *aggregated) {
1928
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 338859 times.
338859 assert(thd != nullptr);
1929
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 338859 times.
338859 assert(aggregated != nullptr);
1930 338859 *aggregated = thd->status_var_aggregated;
1931 338859 return &thd->status_var;
1932 }
1933
1934 #ifndef NDEBUG
1935 18856315 bool thd_mem_cnt_alloc(THD *thd, size_t size, const char *key_name) {
1936 18856315 thd->current_key_name = key_name;
1937 18856315 return thd->m_mem_cnt.alloc_cnt(size);
1938 }
1939 #else
1940 bool thd_mem_cnt_alloc(THD *thd, size_t size) {
1941 return thd->m_mem_cnt.alloc_cnt(size);
1942 }
1943 #endif
1944
1945 18027446 void thd_mem_cnt_free(THD *thd, size_t size) { thd->m_mem_cnt.free_cnt(size); }
1946
1947 9327 static void option_error_reporter(enum loglevel level, uint ecode, ...) {
1948 va_list args;
1949 9327 va_start(args, ecode);
1950
1951 /*
1952 Don't print warnings for --loose options during initialize.
1953 */
1954
5/6
✓ Branch 0 taken 9291 times.
✓ Branch 1 taken 36 times.
✓ Branch 2 taken 71 times.
✓ Branch 3 taken 9220 times.
✓ Branch 4 taken 71 times.
✗ Branch 5 not taken.
9327 if (level == ERROR_LEVEL || !opt_initialize || (log_error_verbosity > 1)) {
1955
1/2
✓ Branch 0 taken 9327 times.
✗ Branch 1 not taken.
9327 error_log_print(level, ecode, args);
1956 }
1957 9327 va_end(args);
1958 9327 }
1959
1960 /**
1961 Character set and collation error reporter that prints to sql error log.
1962 @param level log message level
1963 @param ecode Error code of the error message.
1964
1965 This routine is used to print character set and collation
1966 warnings and errors inside an already running mysqld server,
1967 e.g. when a character set or collation is requested for the very first time
1968 and its initialization does not go well for some reasons.
1969 */
1970
1971 5 static void charset_error_reporter(enum loglevel level, uint ecode, ...) {
1972 va_list args;
1973 5 va_start(args, ecode);
1974
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 error_log_print(level, ecode, args);
1975 5 va_end(args);
1976 5 }
1977
1978 struct rand_struct sql_rand; ///< used by sql_class.cc:THD::THD()
1979
1980 #ifndef _WIN32
1981 PasswdValue user_info;
1982 static my_thread_t main_thread_id;
1983 #endif // !_WIN32
1984
1985 /* OS specific variables */
1986
1987 #ifdef _WIN32
1988 static bool mysqld_early_option = false;
1989 static bool windows_service = false;
1990 static bool use_opt_args;
1991 static int opt_argc;
1992 static char **opt_argv;
1993 static char **my_global_argv = nullptr;
1994 static int my_global_argc;
1995
1996 static mysql_mutex_t LOCK_handler_count;
1997 static mysql_cond_t COND_handler_count;
1998 static HANDLE hEventShutdown;
1999 static HANDLE hEventRestart;
2000 const char *shared_memory_base_name = default_shared_memory_base_name;
2001 bool opt_enable_shared_memory;
2002 static char shutdown_event_name[40];
2003 static char restart_event_name[40];
2004 static NTService Service; ///< Service object for WinNT
2005 #endif /* _WIN32 */
2006
2007 /**
2008 Flag indicating if dynamic plugins have been loaded. Only to be accessed
2009 by main thread.
2010 */
2011 bool dynamic_plugins_are_initialized = false;
2012
2013 #ifndef NDEBUG
2014 static const char *default_dbug_option;
2015 #endif
2016
2017 bool opt_use_ssl = true;
2018 bool opt_use_admin_ssl = true;
2019 ulong opt_ssl_fips_mode = SSL_FIPS_MODE_OFF;
2020
2021 /* Function declarations */
2022
2023 static int mysql_init_variables();
2024 static int get_options(int *argc_ptr, char ***argv_ptr);
2025 static void add_terminator(vector<my_option> *options);
2026 extern "C" bool mysqld_get_one_option(int, const struct my_option *, char *);
2027 static void set_server_version(void);
2028 static int init_thread_environment();
2029 static const char *get_relative_path(const char *path);
2030 static int fix_paths(void);
2031 static int test_if_case_insensitive(const char *dir_name);
2032 static void end_ssl();
2033 static void delete_dictionary_tablespace();
2034
2035 extern "C" void *signal_hand(void *arg);
2036 static bool pid_file_created = false;
2037 static void usage(void);
2038 static void clean_up_mutexes(void);
2039 static bool create_pid_file();
2040 [[noreturn]] static void mysqld_exit(int exit_code);
2041 static void delete_pid_file(myf flags);
2042 static void clean_up(bool print_message);
2043 static int handle_early_options();
2044 static void adjust_related_options(ulong *requested_open_files);
2045 static void process_bootstrap();
2046 #ifdef HAVE_PSI_INTERFACE
2047 static void init_server_psi_keys();
2048 #endif
2049
2050 /**
2051 Notify any waiters that the server components have been initialized.
2052 Used by the signal handler thread and by Cluster.
2053
2054 @see signal_hand
2055 */
2056
2057 9577 static void server_components_initialized() {
2058 9577 mysql_mutex_lock(&LOCK_server_started);
2059 9577 mysqld_server_started = true;
2060 9577 mysql_cond_broadcast(&COND_server_started);
2061 9577 mysql_mutex_unlock(&LOCK_server_started);
2062 9577 }
2063
2064 SERVICE_TYPE(mysql_runtime_error) * error_service;
2065 SERVICE_TYPE(mysql_psi_system_v1) * system_service;
2066 SERVICE_TYPE(mysql_rwlock_v1) * rwlock_service;
2067 SERVICE_TYPE_NO_CONST(registry) * srv_registry;
2068 SERVICE_TYPE(dynamic_loader_scheme_file) * scheme_file_srv;
2069 using loader_type_t = SERVICE_TYPE_NO_CONST(dynamic_loader);
2070 using runtime_error_type_t = SERVICE_TYPE_NO_CONST(mysql_runtime_error);
2071 using psi_system_type_t = SERVICE_TYPE_NO_CONST(mysql_psi_system_v1);
2072 using rwlock_type_t = SERVICE_TYPE_NO_CONST(mysql_rwlock_v1);
2073 using loader_scheme_type_t = SERVICE_TYPE_NO_CONST(dynamic_loader_scheme_file);
2074 extern REQUIRES_SERVICE_PLACEHOLDER(mysql_rwlock_v1);
2075 extern REQUIRES_SERVICE_PLACEHOLDER(mysql_psi_system_v1);
2076 extern bool initialize_minimal_chassis(SERVICE_TYPE_NO_CONST(registry) *
2077 *registry);
2078 extern bool deinitialize_minimal_chassis(SERVICE_TYPE_NO_CONST(registry) *
2079 registry);
2080 /*
2081 List of components to be loaded directly using dynamic loader load.
2082 These components should to be present in the plugin directory path.
2083 */
2084 const char *component_urns[] = {"file://component_reference_cache"};
2085 #define NUMBER_OF_COMPONENTS 1
2086
2087 /**
2088 Initializes component infrastructure by bootstrapping core component
2089 subsystem.
2090
2091 @return Status of performed operation
2092 @retval false success
2093 @retval true failure
2094 */
2095 9813 static bool component_infrastructure_init() {
2096 9813 bool retval = false;
2097
2/4
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9813 times.
9813 if (initialize_minimal_chassis(&srv_registry)) {
2098 LogErr(ERROR_LEVEL, ER_COMPONENTS_INFRASTRUCTURE_BOOTSTRAP);
2099 return true;
2100 }
2101 /* Here minimal_chassis dynamic_loader_scheme_file service has
2102 to be acquired */
2103
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 srv_registry->acquire(
2104 "dynamic_loader_scheme_file.mysql_minimal_chassis",
2105 reinterpret_cast<my_h_service *>(
2106 const_cast<loader_scheme_type_t **>(&scheme_file_srv)));
2107
2108
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 srv_registry->acquire("dynamic_loader",
2109 reinterpret_cast<my_h_service *>(
2110 const_cast<loader_type_t **>(&dynamic_loader_srv)));
2111
2112 my_service<SERVICE_TYPE(registry_registration)> registrator(
2113
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 "registry_registration", srv_registry);
2114
2115 // Sets default file scheme loader for MySQL server.
2116
2/4
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9813 times.
✗ Branch 3 not taken.
9813 registrator->set_default(
2117 "dynamic_loader_scheme_file.mysql_server_path_filter");
2118
2119 // Sets default rw_lock for MySQL server.
2120
2/4
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9813 times.
✗ Branch 3 not taken.
9813 registrator->set_default("mysql_rwlock_v1.mysql_server");
2121
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 srv_registry->acquire("mysql_rwlock_v1.mysql_server",
2122 reinterpret_cast<my_h_service *>(
2123 const_cast<rwlock_type_t **>(&rwlock_service)));
2124 9813 mysql_service_mysql_rwlock_v1 =
2125 reinterpret_cast<SERVICE_TYPE(mysql_rwlock_v1) *>(rwlock_service);
2126
2127 // Sets default psi_system event service for MySQL server.
2128
2/4
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9813 times.
✗ Branch 3 not taken.
9813 registrator->set_default("mysql_psi_system_v1.mysql_server");
2129
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 srv_registry->acquire("mysql_psi_system_v1.mysql_server",
2130 reinterpret_cast<my_h_service *>(
2131 const_cast<psi_system_type_t **>(&system_service)));
2132 /* This service variable is needed for mysql_unload_plugin */
2133 9813 mysql_service_mysql_psi_system_v1 =
2134 reinterpret_cast<SERVICE_TYPE(mysql_psi_system_v1) *>(system_service);
2135
2136 // Sets default mysql_runtime_error for MySQL server.
2137
2/4
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9813 times.
✗ Branch 3 not taken.
9813 registrator->set_default("mysql_runtime_error.mysql_server");
2138
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 srv_registry->acquire(
2139 "mysql_runtime_error.mysql_server",
2140 reinterpret_cast<my_h_service *>(
2141 const_cast<runtime_error_type_t **>(&error_service)));
2142 /* This service variable is needed where ever mysql_error_service_printf()
2143 service api is used */
2144 9813 mysql_service_mysql_runtime_error =
2145 reinterpret_cast<SERVICE_TYPE(mysql_runtime_error) *>(error_service);
2146
2147 9813 return retval;
2148 9813 }
2149
2150 /**
2151 This function is used to initialize the mysql_server component services.
2152 */
2153 9215 static void server_component_init() { mysql_comp_sys_var_services_init(); }
2154
2155 /**
2156 Initializes MySQL Server component infrastructure part by initialize of
2157 dynamic loader persistence.
2158
2159 @return Status of performed operation
2160 @retval false success
2161 @retval true failure
2162 */
2163
2164 9215 static bool mysql_component_infrastructure_init() {
2165 /* We need a temporary THD during boot */
2166
1/2
✓ Branch 0 taken 9215 times.
✗ Branch 1 not taken.
9215 Auto_THD thd;
2167 9215 Disable_autocommit_guard autocommit_guard(thd.thd);
2168 dd::cache::Dictionary_client::Auto_releaser scope_releaser(
2169
1/2
✓ Branch 0 taken 9215 times.
✗ Branch 1 not taken.
9215 thd.thd->dd_client());
2170
2/4
✓ Branch 0 taken 9215 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9215 times.
9215 if (persistent_dynamic_loader_init(thd.thd)) {
2171 LogErr(ERROR_LEVEL, ER_COMPONENTS_PERSIST_LOADER_BOOTSTRAP);
2172 trans_rollback_stmt(thd.thd);
2173 // Full rollback in case we have THD::transaction_rollback_request.
2174 trans_rollback(thd.thd);
2175 return true;
2176 }
2177
1/2
✓ Branch 0 taken 9215 times.
✗ Branch 1 not taken.
9215 server_component_init();
2178
4/8
✓ Branch 0 taken 9215 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9215 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9215 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 9215 times.
9215 return trans_commit_stmt(thd.thd) || trans_commit(thd.thd);
2179 9215 }
2180
2181 /**
2182 De-initializes Component infrastructure by de-initialization of the MySQL
2183 Server services (persistent dynamic loader) followed by de-initailization of
2184 the core Components infrostructure.
2185
2186 @return Status of performed operation
2187 @retval false success
2188 @retval true failure
2189 */
2190 8457 static bool component_infrastructure_deinit() {
2191 8457 persistent_dynamic_loader_deinit();
2192 8457 bool retval = false;
2193
2194 8457 srv_registry->release(reinterpret_cast<my_h_service>(
2195 const_cast<loader_scheme_type_t *>(scheme_file_srv)));
2196 8457 srv_registry->release(reinterpret_cast<my_h_service>(
2197 const_cast<loader_type_t *>(dynamic_loader_srv)));
2198 8457 srv_registry->release(reinterpret_cast<my_h_service>(
2199 const_cast<runtime_error_type_t *>(error_service)));
2200 8457 srv_registry->release(reinterpret_cast<my_h_service>(
2201 const_cast<psi_system_type_t *>(system_service)));
2202 8457 srv_registry->release(reinterpret_cast<my_h_service>(
2203 const_cast<rwlock_type_t *>(rwlock_service)));
2204
2205
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8457 times.
8457 if (deinitialize_minimal_chassis(srv_registry)) {
2206 LogErr(ERROR_LEVEL, ER_COMPONENTS_INFRASTRUCTURE_SHUTDOWN);
2207 retval = true;
2208 }
2209 8457 return retval;
2210 }
2211
2212 9813 static bool initialize_manifest_file_components() {
2213 /*
2214 Read components from manifest file
2215
2216 Note that the word 'components' is used differently in the server.
2217 Here we address the component service infrastructure, but in other places,
2218 like init_server_components() the word is used in bit different context
2219 and may mean general idea of modularity.
2220 */
2221
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9813 times.
9813 assert(strlen(mysql_real_data_home) > 0);
2222
2/4
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9813 times.
✗ Branch 3 not taken.
19626 g_deployed_components =
2223
2/4
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9813 times.
✗ Branch 3 not taken.
9813 new (std::nothrow) Deployed_components(my_progname, mysql_real_data_home);
2224
2/4
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9813 times.
19626 if (g_deployed_components == nullptr ||
2225
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9813 times.
9813 g_deployed_components->valid() == false) {
2226 /*Error would have been raised by Deployed_components constructor */
2227 g_deployed_components = nullptr;
2228 return true;
2229 }
2230 9813 return false;
2231 }
2232
2233 8457 static void deinitialize_manifest_file_components() {
2234
1/2
✓ Branch 0 taken 8457 times.
✗ Branch 1 not taken.
8457 if (g_deployed_components != nullptr) {
2235 /* Error if any would have been raised */
2236
1/2
✓ Branch 0 taken 8457 times.
✗ Branch 1 not taken.
8457 delete g_deployed_components;
2237 8457 g_deployed_components = nullptr;
2238 }
2239 8457 }
2240
2241 /**
2242 Block and wait until server components have been initialized.
2243 */
2244
2245 9379 static void server_components_init_wait() {
2246 9379 mysql_mutex_lock(&LOCK_server_started);
2247
2/2
✓ Branch 0 taken 8476 times.
✓ Branch 1 taken 9379 times.
17855 while (!mysqld_server_started)
2248 8476 mysql_cond_wait(&COND_server_started, &LOCK_server_started);
2249 9379 mysql_mutex_unlock(&LOCK_server_started);
2250 9379 }
2251
2252 /****************************************************************************
2253 ** Code to end mysqld
2254 ****************************************************************************/
2255
2256 /**
2257 This class implements callback function used by close_connections()
2258 to set KILL_CONNECTION flag on all thds in thd list.
2259 If m_kill_dump_thread_flag is not set it kills all other threads
2260 except dump threads. If this flag is set, it kills dump threads.
2261 */
2262 class Set_kill_conn : public Do_THD_Impl {
2263 private:
2264 int m_dump_thread_count;
2265 bool m_kill_dump_threads_flag;
2266
2267 public:
2268 8053 Set_kill_conn() : m_dump_thread_count(0), m_kill_dump_threads_flag(false) {}
2269
2270 156 void set_dump_thread_flag() { m_kill_dump_threads_flag = true; }
2271
2272 8053 int get_dump_thread_count() const { return m_dump_thread_count; }
2273
2274 16356 void operator()(THD *killing_thd) override {
2275
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16356 times.
16356 DBUG_PRINT("quit", ("Informing thread %u that it's time to die",
2276 killing_thd->thread_id()));
2277
2/2
✓ Branch 0 taken 15515 times.
✓ Branch 1 taken 841 times.
16356 if (!m_kill_dump_threads_flag) {
2278 // We skip slave threads & scheduler on this first loop through.
2279
2/2
✓ Branch 0 taken 1005 times.
✓ Branch 1 taken 14510 times.
15515 if (killing_thd->slave_thread) return;
2280
2281 #ifdef WITH_WSREP
2282 /* skip wsrep system threads as well */
2283
7/10
✓ Branch 0 taken 14510 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 450 times.
✓ Branch 3 taken 14060 times.
✓ Branch 4 taken 450 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 449 times.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 14510 times.
14959 if (WSREP(killing_thd) &&
2284
2/4
✓ Branch 0 taken 449 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 449 times.
449 (wsrep_thd_is_applying(killing_thd) || killing_thd->wsrep_applier))
2285 return;
2286 #endif /* WITH_WSREP */
2287
2288
6/6
✓ Branch 0 taken 14417 times.
✓ Branch 1 taken 93 times.
✓ Branch 2 taken 69 times.
✓ Branch 3 taken 14348 times.
✓ Branch 4 taken 162 times.
✓ Branch 5 taken 14348 times.
28927 if (killing_thd->get_command() == COM_BINLOG_DUMP ||
2289 14417 killing_thd->get_command() == COM_BINLOG_DUMP_GTID) {
2290 162 ++m_dump_thread_count;
2291 162 return;
2292 }
2293
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 14348 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
14348 DBUG_EXECUTE_IF("Check_dump_thread_is_alive", {
2294 assert(killing_thd->get_command() != COM_BINLOG_DUMP &&
2295 killing_thd->get_command() != COM_BINLOG_DUMP_GTID);
2296 };);
2297 }
2298 15189 mysql_mutex_lock(&killing_thd->LOCK_thd_data);
2299
2300
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 15175 times.
15189 if (killing_thd->kill_immunizer) {
2301 /*
2302 If killing_thd is in kill immune mode (i.e. operation on new DD tables
2303 is in progress) then just save state_to_set with THD::kill_immunizer
2304 object.
2305
2306 While exiting kill immune mode, awake() is called again with the killed
2307 state saved in THD::kill_immunizer object.
2308 */
2309 14 killing_thd->kill_immunizer->save_killed_state(THD::KILL_CONNECTION);
2310 } else {
2311 15175 killing_thd->killed = THD::KILL_CONNECTION;
2312
2313
3/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 15169 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
15175 MYSQL_CALLBACK(killing_thd->scheduler, post_kill_notification,
2314 (killing_thd));
2315 }
2316
2317
3/4
✓ Branch 0 taken 15189 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15175 times.
✓ Branch 3 taken 14 times.
15189 if (killing_thd->is_killable && killing_thd->kill_immunizer == nullptr) {
2318 15175 mysql_mutex_lock(&killing_thd->LOCK_current_cond);
2319
2/2
✓ Branch 0 taken 8178 times.
✓ Branch 1 taken 6997 times.
15175 if (killing_thd->current_cond.load()) {
2320 8178 mysql_mutex_lock(killing_thd->current_mutex);
2321 8178 mysql_cond_broadcast(killing_thd->current_cond);
2322 8178 mysql_mutex_unlock(killing_thd->current_mutex);
2323 }
2324 15175 mysql_mutex_unlock(&killing_thd->LOCK_current_cond);
2325 }
2326 15189 mysql_mutex_unlock(&killing_thd->LOCK_thd_data);
2327 }
2328 };
2329
2330 /**
2331 This class implements callback function used by close_connections()
2332 to close vio connection for all thds in thd list
2333 */
2334 class Call_close_conn : public Do_THD_Impl {
2335 public:
2336 8048 Call_close_conn(bool server_shutdown) : is_server_shutdown(server_shutdown) {}
2337
2338 3271 void operator()(THD *closing_thd) override {
2339
2/2
✓ Branch 0 taken 2747 times.
✓ Branch 1 taken 524 times.
3271 if (closing_thd->get_protocol()->connection_alive()) {
2340
1/2
✓ Branch 0 taken 2747 times.
✗ Branch 1 not taken.
2747 LEX_CSTRING main_sctx_user = closing_thd->m_main_security_ctx.user();
2341
9/18
✓ Branch 0 taken 2747 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2747 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2747 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2747 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2747 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2747 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2747 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 2747 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 2747 times.
✗ Branch 17 not taken.
2747 LogErr(WARNING_LEVEL, ER_FORCE_CLOSE_THREAD, my_progname,
2342 (long)closing_thd->thread_id(),
2343 (main_sctx_user.length ? main_sctx_user.str : ""));
2344 /*
2345 Do not generate MYSQL_AUDIT_CONNECTION_DISCONNECT event, when closing
2346 thread close sessions. Each session will generate DISCONNECT event by
2347 itself.
2348 */
2349
1/2
✓ Branch 0 taken 2747 times.
✗ Branch 1 not taken.
2747 close_connection(closing_thd, 0, is_server_shutdown, false);
2350 }
2351 #ifdef WITH_WSREP
2352 /*
2353 * TODO: this code block may turn out redundant. wsrep->disconnect()
2354 * should terminate slave threads gracefully, and we don't need
2355 * to signal them here.
2356 * The code here makes sure mysqld will not hang during shutdown
2357 * even if wsrep provider has problems in shutting down.
2358 */
2359
8/12
✓ Branch 0 taken 3271 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 3259 times.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11 times.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 11 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 3271 times.
3271 if (WSREP(closing_thd) && wsrep_thd_is_applying(closing_thd)) {
2360 sql_print_information("closing wsrep system thread");
2361
2362 mysql_mutex_lock(&closing_thd->LOCK_thd_data);
2363 closing_thd->killed = THD::KILL_CONNECTION;
2364 if (closing_thd->current_cond) {
2365 mysql_mutex_lock(closing_thd->current_mutex);
2366 mysql_cond_broadcast(closing_thd->current_cond);
2367 mysql_mutex_unlock(closing_thd->current_mutex);
2368 }
2369 mysql_mutex_unlock(&closing_thd->LOCK_thd_data);
2370 }
2371 #endif /* WITH_WSREP */
2372 3271 }
2373
2374 private:
2375 bool is_server_shutdown;
2376 };
2377
2378 #ifdef WITH_WSREP
2379 /**
2380 This class implements callback function used by
2381 wsrep_close_client_connections() to set KILL_CONNECTION
2382 flag on all client thds and awake the thread.
2383 */
2384 class Set_wsrep_kill_client_conn : public Do_THD_Impl {
2385 public:
2386 36 Set_wsrep_kill_client_conn() {}
2387
2388 114 virtual void operator()(THD *killing_thd) {
2389
1/2
✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
152 if (killing_thd->get_protocol()->connection_alive() &&
2390
9/12
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 76 times.
✓ Branch 2 taken 28 times.
✓ Branch 3 taken 10 times.
✓ Branch 4 taken 28 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 28 times.
✓ Branch 8 taken 10 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✓ Branch 11 taken 108 times.
190 (WSREP(killing_thd) || wsrep_thd_is_local(killing_thd)) &&
2391
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 32 times.
38 killing_thd != current_thd) {
2392 6 mysql_mutex_lock(&killing_thd->LOCK_thd_data);
2393 6 killing_thd->awake(THD::KILL_CONNECTION);
2394 6 mysql_mutex_unlock(&killing_thd->LOCK_thd_data);
2395 }
2396 114 }
2397 };
2398 /**
2399 This class implements callback function used by close_connections()
2400 to set KILL_CONNECTION flag on all thds in thd list.
2401 If m_kill_dump_thread_flag is not set it kills all other threads
2402 except dump threads. If this flag is set, it kills dump threads.
2403 */
2404 class Set_wsrep_kill_conn : public Do_THD_Impl {
2405 private:
2406 int m_dump_thread_count;
2407 bool m_kill_dump_threads_flag;
2408
2409 public:
2410 Set_wsrep_kill_conn()
2411 : m_dump_thread_count(0), m_kill_dump_threads_flag(false) {}
2412
2413 void set_dump_thread_flag() { m_kill_dump_threads_flag = true; }
2414
2415 int get_dump_thread_count() const { return m_dump_thread_count; }
2416
2417 virtual void operator()(THD *killing_thd) {
2418 DBUG_PRINT("quit", ("Informing thread %u that it's time to die",
2419 killing_thd->thread_id()));
2420 if (!m_kill_dump_threads_flag) {
2421 // We skip slave threads & scheduler on this first loop through.
2422 if (killing_thd->slave_thread) return;
2423 /* skip wsrep system threads as well */
2424 if (WSREP(killing_thd) &&
2425 (wsrep_thd_is_applying(killing_thd) || killing_thd->wsrep_applier))
2426 return;
2427
2428 if (killing_thd->get_command() == COM_BINLOG_DUMP ||
2429 killing_thd->get_command() == COM_BINLOG_DUMP_GTID) {
2430 ++m_dump_thread_count;
2431 return;
2432 }
2433 DBUG_EXECUTE_IF("Check_dump_thread_is_alive", {
2434 assert(killing_thd->get_command() != COM_BINLOG_DUMP &&
2435 killing_thd->get_command() != COM_BINLOG_DUMP_GTID);
2436 };);
2437 }
2438 mysql_mutex_lock(&killing_thd->LOCK_thd_data);
2439 killing_thd->killed = THD::KILL_CONNECTION;
2440 MYSQL_CALLBACK(Connection_handler_manager::event_functions,
2441 post_kill_notification, (killing_thd));
2442 mysql_mutex_lock(&killing_thd->LOCK_current_cond);
2443 if (killing_thd->current_cond) {
2444 mysql_mutex_lock(killing_thd->current_mutex);
2445 mysql_cond_broadcast(killing_thd->current_cond);
2446 mysql_mutex_unlock(killing_thd->current_mutex);
2447 }
2448 mysql_mutex_unlock(&killing_thd->LOCK_current_cond);
2449 mysql_mutex_unlock(&killing_thd->LOCK_thd_data);
2450 }
2451 };
2452
2453 /**
2454 This class implements callback function used by close_connections()
2455 to close vio connection for all thds in thd list
2456 */
2457 class Call_wsrep_close_client_conn : public Do_THD_Impl {
2458 public:
2459 36 Call_wsrep_close_client_conn(bool server_shutdown)
2460 36 : is_server_shutdown(server_shutdown) {}
2461
2462 94 virtual void operator()(THD *closing_thd) {
2463
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
126 if (closing_thd->get_protocol()->connection_alive() &&
2464
8/12
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 62 times.
✓ Branch 2 taken 22 times.
✓ Branch 3 taken 10 times.
✓ Branch 4 taken 22 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 22 times.
✓ Branch 8 taken 10 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 94 times.
158 (WSREP(closing_thd) || wsrep_thd_is_local(closing_thd)) &&
2465
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 closing_thd != current_thd) {
2466 LEX_CSTRING main_sctx_user = closing_thd->m_main_security_ctx.user();
2467 sql_print_warning(ER_DEFAULT(ER_FORCING_CLOSE), my_progname,
2468 closing_thd->thread_id(),
2469 (main_sctx_user.length ? main_sctx_user.str : ""));
2470 /*
2471 Do not generate MYSQL_AUDIT_CONNECTION_DISCONNECT event, when closing
2472 thread close sessions. Each session will generate DISCONNECT event by
2473 itself.
2474 */
2475 close_connection(closing_thd, 0, is_server_shutdown, false);
2476 }
2477 94 }
2478
2479 private:
2480 bool is_server_shutdown;
2481 };
2482
2483 /**
2484 This class implements callback function used by close_connections()
2485 to close all wsrep system threads
2486 */
2487 class Call_wsrep_close_wsrep_threads : public Do_THD_Impl {
2488 public:
2489 468 Call_wsrep_close_wsrep_threads() {}
2490
2491 1213 virtual void operator()(THD *thd) {
2492
2/2
✓ Branch 0 taken 679 times.
✓ Branch 1 taken 534 times.
1213 if (thd->wsrep_applier) {
2493
11/20
✓ Branch 0 taken 53 times.
✓ Branch 1 taken 626 times.
✓ Branch 2 taken 53 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 53 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 53 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 53 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 53 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 53 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 53 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 53 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 53 times.
679 WSREP_DEBUG("Closing applier thread %u", thd->thread_id());
2494 679 mysql_mutex_lock(&thd->LOCK_thd_data);
2495 679 thd->killed = THD::KILL_CONNECTION;
2496
2/2
✓ Branch 0 taken 457 times.
✓ Branch 1 taken 222 times.
679 if (thd->current_cond) {
2497 457 mysql_mutex_lock(thd->current_mutex);
2498 457 mysql_cond_broadcast(thd->current_cond);
2499 457 mysql_mutex_unlock(thd->current_mutex);
2500 }
2501 679 mysql_mutex_unlock(&thd->LOCK_thd_data);
2502 }
2503 1213 }
2504 };
2505
2506 /**
2507 This class implements callback function used by close_connections()
2508 to wait for committing transactions
2509 */
2510 class Find_thd_committing : public Find_THD_Impl {
2511 public:
2512 Find_thd_committing() {}
2513
2514 virtual bool operator()(THD *thd) {
2515 if (WSREP(thd) && wsrep_thd_is_local(thd) &&
2516 thd->wsrep_trx().state() == wsrep::transaction::s_committing) {
2517 return true;
2518 }
2519 return false;
2520 }
2521 };
2522
2523 enum wsrep_thd_type { APPLIER, COMMITTING };
2524
2525 class Find_wsrep_thd : public Find_THD_Impl {
2526 public:
2527 1485 Find_wsrep_thd(enum wsrep_thd_type type) : m_type(type) {}
2528 3577 virtual bool operator()(THD *thd) {
2529
6/8
✓ Branch 0 taken 3577 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3515 times.
✓ Branch 3 taken 62 times.
✓ Branch 4 taken 3515 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3496 times.
✓ Branch 7 taken 19 times.
3577 if (WSREP(thd)) {
2530
2/3
✓ Branch 0 taken 2888 times.
✓ Branch 1 taken 608 times.
✗ Branch 2 not taken.
3496 switch (m_type) {
2531 2888 case APPLIER:
2532 2888 return (thd->wsrep_applier);
2533 608 case COMMITTING:
2534 608 return (thd->wsrep_trx().state() == wsrep::transaction::s_committing);
2535 }
2536
3/4
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 62 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 19 times.
81 } else if (!WSREP_ON) {
2537 /* case when user try to set wsrep_provider = none w/o server shutdown */
2538
1/2
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
62 switch (m_type) {
2539 62 case APPLIER:
2540 62 return thd->wsrep_applier;
2541 default:
2542 return false;
2543 }
2544 }
2545 19 return false;
2546 }
2547
2548 private:
2549 enum wsrep_thd_type m_type;
2550 bool is_server_shutdown;
2551 };
2552
2553 class Count_wsrep_applier_threads : public Do_THD_Impl {
2554 public:
2555 Count_wsrep_applier_threads() : m_count() {}
2556
2557 void reset() { m_count = 0; }
2558
2559 bool done(int threshold_count) { return (m_count <= threshold_count); }
2560
2561 virtual void operator()(THD *killing_thd) {
2562 if (killing_thd->wsrep_applier) m_count++;
2563 }
2564
2565 private:
2566 int m_count;
2567 };
2568 #endif /* WITH_WSREP */
2569
2570 8053 static void close_connections(void) {
2571
1/2
✓ Branch 0 taken 8053 times.
✗ Branch 1 not taken.
8053 DBUG_TRACE;
2572 #ifdef WITH_WSREP
2573
12/24
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 7997 times.
✓ Branch 2 taken 56 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 56 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 56 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 56 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 56 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 56 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 56 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 56 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 56 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 56 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
8053 WSREP_DEBUG("Closing connection (close_connections)");
2574 #endif /* WITH_WSREP */
2575
4/6
✓ Branch 0 taken 8053 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1499 times.
✓ Branch 3 taken 6554 times.
✓ Branch 4 taken 1499 times.
✗ Branch 5 not taken.
8053 (void)RUN_HOOK(server_state, before_server_shutdown, (nullptr));
2576
2577
1/2
✓ Branch 0 taken 8053 times.
✗ Branch 1 not taken.
8053 Per_thread_connection_handler::kill_blocked_pthreads();
2578
2579 8053 uint dump_thread_count = 0;
2580 8053 uint dump_thread_kill_retries = 8;
2581
2582 // Close listeners.
2583
2/2
✓ Branch 0 taken 7855 times.
✓ Branch 1 taken 198 times.
8053 if (mysqld_socket_acceptor != nullptr)
2584
1/2
✓ Branch 0 taken 7855 times.
✗ Branch 1 not taken.
7855 mysqld_socket_acceptor->close_listener();
2585 #ifdef _WIN32
2586 if (named_pipe_acceptor != NULL) named_pipe_acceptor->close_listener();
2587
2588 if (shared_mem_acceptor != NULL) shared_mem_acceptor->close_listener();
2589 #endif
2590
2591 /*
2592 First signal all threads that it's time to die
2593 This will give the threads some time to gracefully abort their
2594 statements and inform their clients that the server is about to die.
2595 */
2596
2597 8053 Global_THD_manager *thd_manager = Global_THD_manager::get_instance();
2598
8/16
✓ Branch 0 taken 8053 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8053 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8053 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8053 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 8053 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 8053 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 8053 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 8053 times.
✗ Branch 15 not taken.
8053 LogErr(INFORMATION_LEVEL, ER_DEPART_WITH_GRACE,
2599 static_cast<int>(thd_manager->get_thd_count()));
2600
2601
1/2
✓ Branch 0 taken 8053 times.
✗ Branch 1 not taken.
8053 Set_kill_conn set_kill_conn;
2602
1/2
✓ Branch 0 taken 8053 times.
✗ Branch 1 not taken.
8053 thd_manager->do_for_all_thd(&set_kill_conn);
2603
8/16
✓ Branch 0 taken 8053 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8053 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8053 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8053 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 8053 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 8053 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 8053 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 8053 times.
✗ Branch 15 not taken.
8053 LogErr(INFORMATION_LEVEL, ER_SHUTTING_DOWN_SLAVE_THREADS);
2604
1/2
✓ Branch 0 taken 8053 times.
✗ Branch 1 not taken.
8053 end_slave();
2605
2606
2/2
✓ Branch 0 taken 156 times.
✓ Branch 1 taken 7897 times.
8053 if (set_kill_conn.get_dump_thread_count()) {
2607 /*
2608 Replication dump thread should be terminated after the clients are
2609 terminated. Wait for few more seconds for other sessions to end.
2610 */
2611
5/6
✓ Branch 0 taken 1404 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1248 times.
✓ Branch 3 taken 156 times.
✓ Branch 4 taken 1248 times.
✓ Branch 5 taken 156 times.
1404 while (thd_manager->get_thd_count() > dump_thread_count &&
2612 dump_thread_kill_retries) {
2613
1/2
✓ Branch 0 taken 1248 times.
✗ Branch 1 not taken.
1248 sleep(1);
2614 1248 dump_thread_kill_retries--;
2615 }
2616 156 set_kill_conn.set_dump_thread_flag();
2617
1/2
✓ Branch 0 taken 156 times.
✗ Branch 1 not taken.
156 thd_manager->do_for_all_thd(&set_kill_conn);
2618 }
2619
2620 // Disable the event scheduler
2621
1/2
✓ Branch 0 taken 8053 times.
✗ Branch 1 not taken.
8053 Events::stop();
2622
2623
3/4
✓ Branch 0 taken 3195 times.
✓ Branch 1 taken 4858 times.
✓ Branch 2 taken 3191 times.
✗ Branch 3 not taken.
8053 if (thd_manager->get_thd_count() > 0) sleep(2); // Give threads time to die
2624
2625 /*
2626 Force remaining threads to die by closing the connection to the client
2627 This will ensure that threads that are waiting for a command from the
2628 client on a blocking read call are aborted.
2629 */
2630
2631
8/16
✓ Branch 0 taken 8049 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8049 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8049 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8049 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 8049 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 8049 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 8049 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 8049 times.
✗ Branch 15 not taken.
8049 LogErr(INFORMATION_LEVEL, ER_DISCONNECTING_REMAINING_CLIENTS,
2632 static_cast<int>(thd_manager->get_thd_count()));
2633
2634
1/2
✓ Branch 0 taken 8048 times.
✗ Branch 1 not taken.
8048 Call_close_conn call_close_conn(true);
2635
1/2
✓ Branch 0 taken 8048 times.
✗ Branch 1 not taken.
8048 thd_manager->do_for_all_thd(&call_close_conn);
2636
2637
4/6
✓ Branch 0 taken 8048 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1499 times.
✓ Branch 3 taken 6549 times.
✓ Branch 4 taken 1499 times.
✗ Branch 5 not taken.
8048 (void)RUN_HOOK(server_state, after_server_shutdown, (nullptr));
2638
2639 /*
2640 All threads have now been aborted. Stop event scheduler thread
2641 after aborting all client connections, otherwise user may
2642 start/stop event scheduler after Events::deinit() deallocates
2643 scheduler object(static member in Events class)
2644 */
2645
1/2
✓ Branch 0 taken 8048 times.
✗ Branch 1 not taken.
8048 Events::deinit();
2646
3/8
✓ Branch 0 taken 8048 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8048 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 8048 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
8048 DBUG_PRINT("quit", ("Waiting for threads to die (count=%u)",
2647 thd_manager->get_thd_count()));
2648
1/2
✓ Branch 0 taken 8048 times.
✗ Branch 1 not taken.
8048 thd_manager->wait_till_no_thd();
2649 /*
2650 Connection threads might take a little while to go down after removing from
2651 global thread list. Give it some time.
2652 */
2653
1/2
✓ Branch 0 taken 8048 times.
✗ Branch 1 not taken.
8048 Connection_handler_manager::wait_till_no_connection();
2654
2655
1/2
✓ Branch 0 taken 8048 times.
✗ Branch 1 not taken.
8048 delete_slave_info_objects();
2656
3/8
✓ Branch 0 taken 8048 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8048 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 8048 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
8048 DBUG_PRINT("quit", ("close_connections thread"));
2657 8048 }
2658
2659 55 bool signal_restart_server() {
2660
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 51 times.
55 if (!is_mysqld_managed()) {
2661 4 my_error(ER_RESTART_SERVER_FAILED, MYF(0),
2662 "mysqld is not managed by supervisor process");
2663 4 return true;
2664 }
2665
2666 #ifdef _WIN32
2667 if (!SetEvent(hEventRestart)) {
2668 LogErr(ERROR_LEVEL, ER_SET_EVENT_FAILED, GetLastError());
2669 my_error(ER_RESTART_SERVER_FAILED, MYF(0), "Internal operation failure");
2670 return true;
2671 }
2672 #else
2673
2674
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
51 if (pthread_kill(signal_thread_id.thread, SIGUSR2)) {
2675 DBUG_PRINT("error", ("Got error %d from pthread_kill", errno));
2676 my_error(ER_RESTART_SERVER_FAILED, MYF(0), "Internal operation failure");
2677 return true;
2678 }
2679 #endif
2680 51 return false;
2681 }
2682
2683 7804 void kill_mysql(void) {
2684
1/2
✓ Branch 0 taken 7804 times.
✗ Branch 1 not taken.
7804 DBUG_TRACE;
2685
2686
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 7800 times.
7804 if (!mysqld_server_started) {
2687 4 mysqld_process_must_end_at_startup = true;
2688 4 return;
2689 }
2690 #if defined(_WIN32)
2691 {
2692 if (!SetEvent(hEventShutdown)) {
2693 DBUG_PRINT("error", ("Got error: %ld from SetEvent", GetLastError()));
2694 }
2695 /*
2696 or:
2697 HANDLE hEvent=OpenEvent(0, false, "MySqlShutdown");
2698 SetEvent(hEventShutdown);
2699 CloseHandle(hEvent);
2700 */
2701 }
2702 #else
2703
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7800 times.
7800 if (pthread_kill(signal_thread_id.thread, SIGTERM)) {
2704 DBUG_PRINT("error", ("Got error %d from pthread_kill",
2705 errno)); /* purecov: inspected */
2706 }
2707 #endif
2708
5/8
✓ Branch 0 taken 7800 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7800 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 7799 times.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
7800 DBUG_PRINT("quit", ("After pthread_kill"));
2709
2/2
✓ Branch 0 taken 7800 times.
✓ Branch 1 taken 4 times.
7804 }
2710
2711 #ifdef WITH_WSREP
2712 624 void unireg_abort(int exit_code) {
2713 #else
2714 static void unireg_abort(int exit_code) {
2715 #endif /* WITH_WSREP */
2716
1/2
✓ Branch 0 taken 624 times.
✗ Branch 1 not taken.
624 DBUG_TRACE;
2717
2718
2/2
✓ Branch 0 taken 221 times.
✓ Branch 1 taken 403 times.
624 if (errno) {
2719
1/2
✓ Branch 0 taken 221 times.
✗ Branch 1 not taken.
221 sysd::notify("ERRNO=", errno, "\n");
2720 }
2721
2722
5/6
✓ Branch 0 taken 213 times.
✓ Branch 1 taken 411 times.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 196 times.
✓ Branch 4 taken 17 times.
✗ Branch 5 not taken.
624 if (opt_initialize && exit_code && !opt_validate_config)
2723
12/20
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9 times.
✓ Branch 5 taken 8 times.
✓ Branch 6 taken 17 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 17 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 17 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 17 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 17 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 9 times.
✓ Branch 17 taken 8 times.
✓ Branch 18 taken 17 times.
✗ Branch 19 not taken.
17 LogErr(ERROR_LEVEL,
2724 mysql_initialize_directory_freshly_created
2725 ? ER_DATA_DIRECTORY_UNUSABLE_DELETABLE
2726 : ER_DATA_DIRECTORY_UNUSABLE,
2727 mysql_real_data_home);
2728
2729 // At this point it does not make sense to buffer more messages.
2730 // Just flush what we have and write directly to stderr.
2731
1/2
✓ Branch 0 taken 624 times.
✗ Branch 1 not taken.
624 flush_error_log_messages();
2732
2733
3/4
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 610 times.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
624 if (opt_help) usage();
2734
2735 bool daemon_launcher_quiet =
2736
5/6
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 620 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 1 times.
627 (IF_WIN(false, opt_daemonize) && !mysqld::runtime::is_daemon() &&
2737
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 !is_help_or_validate_option());
2738
2739
12/20
✓ Branch 0 taken 621 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 385 times.
✓ Branch 3 taken 236 times.
✓ Branch 4 taken 385 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 385 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 385 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 385 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 385 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 385 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 385 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 385 times.
✗ Branch 19 not taken.
624 if (!daemon_launcher_quiet && exit_code) LogErr(ERROR_LEVEL, ER_ABORTING);
2740
2741 #ifdef WITH_WSREP
2742
7/8
✓ Branch 0 taken 405 times.
✓ Branch 1 taken 219 times.
✓ Branch 2 taken 22 times.
✓ Branch 3 taken 383 times.
✓ Branch 4 taken 22 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 621 times.
646 if (WSREP_ON && Wsrep_server_state::has_instance() &&
2743
3/4
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 19 times.
22 Wsrep_server_state::instance().state() !=
2744 wsrep::server_state::s_disconnected) {
2745
1/24
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
3 WSREP_DEBUG("Initiating abort (unireg_abort)");
2746
2747 3 wsrep_unireg_abort = true;
2748
2749 /* Cancel the SST script if it is running: */
2750
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 wsrep_sst_cancel(true);
2751
2752 /* This is an abort situation, we cannot expect to gracefully close all
2753 * wsrep threads here, we can only diconnect from service */
2754
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 wsrep_close_client_connections(false, true);
2755
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 wsrep_close_threads(NULL);
2756
2757
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 auto state = Wsrep_server_state::instance().state();
2758
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 if (state != wsrep::server_state::s_disconnected &&
2759 state != wsrep::server_state::s_disconnecting) {
2760
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 Wsrep_server_state::instance().disconnect();
2761 }
2762
2763
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 THD *thd = current_thd;
2764
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (thd) {
2765 Global_THD_manager *thd_manager = Global_THD_manager::get_instance();
2766 WSREP_DEBUG("Closing aborting applier THD: %u", thd->thread_id());
2767 thd->release_resources();
2768 thd_manager->remove_thd(thd);
2769
2770 delete thd;
2771 }
2772
2773
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 wsrep_wait_appliers_close(NULL);
2774
11/22
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 3 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 3 times.
✗ Branch 21 not taken.
3 WSREP_INFO("Service disconnected.");
2775
2776
11/22
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 3 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 3 times.
✗ Branch 21 not taken.
3 WSREP_INFO("Waiting to close threads......");
2777
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 sleep(5); /* so give some time to exit for those which can */
2778
11/22
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 3 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 3 times.
✗ Branch 21 not taken.
3 WSREP_INFO("Some threads may fail to exit.");
2779 }
2780 #endif /* WITH_WSREP */
2781
1/2
✓ Branch 0 taken 624 times.
✗ Branch 1 not taken.
624 mysql_audit_notify(MYSQL_AUDIT_SERVER_SHUTDOWN_SHUTDOWN,
2782 MYSQL_AUDIT_SERVER_SHUTDOWN_REASON_ABORT, exit_code);
2783 #ifndef _WIN32
2784
2/2
✓ Branch 0 taken 202 times.
✓ Branch 1 taken 422 times.
624 if (signal_thread_id.thread != 0) {
2785 // Make sure the signal thread isn't blocked when we are trying to exit.
2786
1/2
✓ Branch 0 taken 202 times.
✗ Branch 1 not taken.
202 server_components_initialized();
2787
2788 202 pthread_kill(signal_thread_id.thread, SIGTERM);
2789
1/2
✓ Branch 0 taken 202 times.
✗ Branch 1 not taken.
202 my_thread_join(&signal_thread_id, nullptr);
2790 }
2791 624 signal_thread_id.thread = 0;
2792
2793
3/4
✓ Branch 0 taken 624 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 623 times.
624 if (mysqld::runtime::is_daemon()) {
2794
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 mysqld::runtime::signal_parent(pipe_write_fd, 0);
2795 }
2796 #endif
2797
7/8
✓ Branch 0 taken 605 times.
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 602 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 220 times.
✓ Branch 5 taken 382 times.
✓ Branch 6 taken 624 times.
✗ Branch 7 not taken.
844 clean_up(!is_help_or_validate_option() && !daemon_launcher_quiet &&
2798
2/2
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 195 times.
220 (exit_code || !opt_initialize)); /* purecov: inspected */
2799
3/8
✓ Branch 0 taken 624 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 624 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
624 DBUG_PRINT("quit", ("done with cleanup in unireg_abort"));
2800 624 mysqld_exit(exit_code);
2801 }
2802
2803 11 void clean_up_mysqld_mutexes() { clean_up_mutexes(); }
2804
2805 8457 static void mysqld_exit(int exit_code) {
2806
4/6
✓ Branch 0 taken 8457 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8406 times.
✓ Branch 3 taken 51 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 51 times.
8457 assert(
2807 (exit_code >= MYSQLD_SUCCESS_EXIT && exit_code <= MYSQLD_ABORT_EXIT) ||
2808 exit_code == MYSQLD_RESTART_EXIT);
2809 #ifdef WITH_WSREP
2810 8457 wsrep_deinit_server();
2811 #endif /* WITH_WSREP */
2812 8457 mysql_audit_finalize();
2813 8457 Srv_session::module_deinit();
2814 8457 delete_optimizer_cost_module();
2815 8457 clean_up_mutexes();
2816
2/2
✓ Branch 0 taken 235 times.
✓ Branch 1 taken 8222 times.
8457 my_end(opt_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
2817 8457 destroy_error_log();
2818 8457 log_error_read_log_exit();
2819 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
2820 8457 shutdown_performance_schema();
2821 #endif
2822
2823 #ifdef WITH_LOCK_ORDER
2824 LO_cleanup();
2825 #endif
2826
2827 #if defined(_WIN32)
2828 if (hEventShutdown) CloseHandle(hEventShutdown);
2829 close_service_status_pipe_in_mysqld();
2830 #endif // _WIN32
2831
2832 8457 exit(exit_code); /* purecov: inspected */
2833 }
2834
2835 /**
2836 GTID cleanup destroys objects and reset their pointer.
2837 Function is reentrant.
2838 */
2839 8468 void gtid_server_cleanup() {
2840
2/2
✓ Branch 0 taken 8412 times.
✓ Branch 1 taken 56 times.
8468 if (gtid_state != nullptr) {
2841
1/2
✓ Branch 0 taken 8412 times.
✗ Branch 1 not taken.
8412 delete gtid_state;
2842 8412 gtid_state = nullptr;
2843 }
2844
2/2
✓ Branch 0 taken 8412 times.
✓ Branch 1 taken 56 times.
8468 if (global_sid_map != nullptr) {
2845
1/2
✓ Branch 0 taken 8412 times.
✗ Branch 1 not taken.
8412 delete global_sid_map;
2846 8412 global_sid_map = nullptr;
2847 }
2848
2/2
✓ Branch 0 taken 8412 times.
✓ Branch 1 taken 56 times.
8468 if (global_sid_lock != nullptr) {
2849
1/2
✓ Branch 0 taken 8412 times.
✗ Branch 1 not taken.
8412 delete global_sid_lock;
2850 8412 global_sid_lock = nullptr;
2851 }
2852
2/2
✓ Branch 0 taken 8412 times.
✓ Branch 1 taken 56 times.
8468 if (gtid_table_persistor != nullptr) {
2853
1/2
✓ Branch 0 taken 8412 times.
✗ Branch 1 not taken.
8412 delete gtid_table_persistor;
2854 8412 gtid_table_persistor = nullptr;
2855 }
2856 8468 }
2857
2858 /**
2859 GTID initialization.
2860
2861 @return true if allocation does not succeed
2862 false if OK
2863 */
2864 9768 bool gtid_server_init() {
2865 9768 global_gtid_mode.set(
2866 static_cast<Gtid_mode::value_type>(Gtid_mode::sysvar_mode));
2867 9768 bool res = (!(global_sid_lock = new Checkable_rwlock(
2868 #ifdef HAVE_PSI_INTERFACE
2869 key_rwlock_global_sid_lock
2870 #endif
2871
1/2
✓ Branch 0 taken 9768 times.
✗ Branch 1 not taken.
9768 )) ||
2872
2/4
✓ Branch 0 taken 9768 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9768 times.
✗ Branch 3 not taken.
9768 !(global_sid_map = new Sid_map(global_sid_lock)) ||
2873
3/6
✓ Branch 0 taken 9768 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9768 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9768 times.
✗ Branch 5 not taken.
29304 !(gtid_state = new Gtid_state(global_sid_lock, global_sid_map)) ||
2874
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9768 times.
9768 !(gtid_table_persistor = new Gtid_table_persistor()));
2875
2876
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9768 times.
9768 if (res) {
2877 gtid_server_cleanup();
2878 }
2879 9768 return res;
2880 }
2881
2882 // Free connection acceptors
2883 8457 static void free_connection_acceptors() {
2884
2/2
✓ Branch 0 taken 7873 times.
✓ Branch 1 taken 584 times.
8457 delete mysqld_socket_acceptor;
2885 8457 mysqld_socket_acceptor = nullptr;
2886
2887 #ifdef _WIN32
2888 delete named_pipe_acceptor;
2889 named_pipe_acceptor = NULL;
2890 delete shared_mem_acceptor;
2891 shared_mem_acceptor = NULL;
2892 #endif
2893 8457 }
2894
2895 8470 static void clean_up(bool print_message) {
2896
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8470 times.
8470 DBUG_PRINT("exit", ("clean_up"));
2897
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8470 times.
8470 if (cleanup_done++) return; /* purecov: inspected */
2898
2899 8470 ha_pre_dd_shutdown();
2900 8457 dd::shutdown();
2901
2902 8457 Events::deinit();
2903 8457 stop_handle_manager();
2904
2905 8457 memcached_shutdown();
2906
2907 8457 release_keyring_handles();
2908 8457 keyring_lockable_deinit();
2909
2910 /*
2911 make sure that handlers finish up
2912 what they have that is dependent on the binlog
2913 */
2914
5/8
✓ Branch 0 taken 8240 times.
✓ Branch 1 taken 217 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8240 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 8240 times.
✓ Branch 7 taken 217 times.
8457 if (print_message && (!is_help_or_validate_option() || opt_verbose))
2915
7/14
✓ Branch 0 taken 8240 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8240 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8240 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8240 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 8240 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 8240 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 8240 times.
✗ Branch 13 not taken.
8240 LogErr(INFORMATION_LEVEL, ER_BINLOG_END);
2916 8457 ha_binlog_end(current_thd);
2917
2918 8457 injector::free_instance();
2919 8457 mysql_bin_log.cleanup();
2920
2921 8457 udf_load_service.deinit();
2922
2/2
✓ Branch 0 taken 8122 times.
✓ Branch 1 taken 335 times.
8457 delete rpl_source_io_monitor;
2923 8457 rpl_source_io_monitor = nullptr;
2924
2/2
✓ Branch 0 taken 8122 times.
✓ Branch 1 taken 335 times.
8457 delete rpl_acf_configuration_handler;
2925 8457 rpl_acf_configuration_handler = nullptr;
2926
2927
2/2
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 8423 times.
8457 if (use_slave_mask) bitmap_free(&slave_error_mask);
2928 8457 my_tz_free();
2929 8457 servers_free(true);
2930 8457 acl_free(true);
2931 8457 grant_free();
2932 8457 hostname_cache_free();
2933 8457 range_optimizer_free();
2934 8457 item_func_sleep_free();
2935 8457 lex_free(); /* Free some memory */
2936 8457 item_create_cleanup();
2937
2/2
✓ Branch 0 taken 8196 times.
✓ Branch 1 taken 261 times.
8457 if (!opt_noacl) udf_unload_udfs();
2938 8457 table_def_start_shutdown();
2939 8457 delegates_shutdown();
2940 8457 plugin_shutdown();
2941 8457 gtid_server_cleanup(); // after plugin_shutdown
2942 8457 delete_optimizer_cost_module();
2943 8457 ha_end();
2944
2/2
✓ Branch 0 taken 532 times.
✓ Branch 1 taken 7925 times.
8457 if (tc_log) {
2945 532 tc_log->close();
2946 532 tc_log = nullptr;
2947 }
2948
2949
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 8435 times.
8457 if (dd::upgrade_57::in_progress()) delete_dictionary_tablespace();
2950
2951 8457 Recovered_xa_transactions::destroy();
2952 8457 delegates_destroy();
2953 8457 xa::Transaction_cache::dispose();
2954 8457 MDL_context_backup_manager::destroy();
2955 8457 table_def_free();
2956 8457 mdl_destroy();
2957 8457 key_caches.delete_elements();
2958 8457 multi_keycache_free();
2959 8457 query_logger.cleanup();
2960 8457 free_tmpdir(&mysql_tmpdir_list);
2961 8457 my_free(opt_bin_logname);
2962 8457 free_max_user_conn();
2963 8457 free_global_user_stats();
2964 8457 free_global_client_stats();
2965 8457 free_global_thread_stats();
2966 8457 free_global_table_stats();
2967 8457 free_global_index_stats();
2968
1/2
✓ Branch 0 taken 8457 times.
✗ Branch 1 not taken.
8457 delete binlog_filter;
2969 8457 rpl_channel_filters.clean_up();
2970 8457 end_ssl();
2971 8457 vio_end();
2972 8457 u_cleanup();
2973 #if defined(ENABLED_DEBUG_SYNC)
2974 /* End the debug sync facility. See debug_sync.cc. */
2975 8457 debug_sync_end();
2976 #endif /* defined(ENABLED_DEBUG_SYNC) */
2977
2978 8457 delete_pid_file(MYF(0));
2979
2980
5/6
✓ Branch 0 taken 8240 times.
✓ Branch 1 taken 217 times.
✓ Branch 2 taken 8203 times.
✓ Branch 3 taken 37 times.
✓ Branch 4 taken 8203 times.
✗ Branch 5 not taken.
8457 if (print_message && my_default_lc_messages && server_start_time)
2981
7/14
✓ Branch 0 taken 8203 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8203 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8203 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8203 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 8203 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 8203 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 8203 times.
✗ Branch 13 not taken.
8203 LogErr(SYSTEM_LEVEL, ER_SERVER_SHUTDOWN_COMPLETE, my_progname,
2982 server_version, MYSQL_COMPILATION_COMMENT_SERVER);
2983 8457 cleanup_errmsgs();
2984
2985 8457 sysd::notify("STATUS=Server shutdown complete");
2986
2987 8457 free_connection_acceptors();
2988 8457 Connection_handler_manager::destroy_instance();
2989
2990
6/6
✓ Branch 0 taken 8438 times.
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 8226 times.
✓ Branch 3 taken 212 times.
✓ Branch 4 taken 8226 times.
✓ Branch 5 taken 231 times.
8457 if (!is_help_or_validate_option() && !opt_initialize)
2991 8226 resourcegroups::Resource_group_mgr::destroy_instance();
2992 8457 mysql_client_plugin_deinit();
2993
2994 8457 Global_THD_manager::destroy_instance();
2995
2996 8457 my_free(const_cast<char *>(log_bin_basename));
2997 8457 my_free(const_cast<char *>(log_bin_index));
2998 8457 my_free(const_cast<char *>(relay_log_basename));
2999 8457 my_free(const_cast<char *>(relay_log_index));
3000 8457 free_list(opt_early_plugin_load_list_ptr);
3001 8457 free_list(opt_plugin_load_list_ptr);
3002
3003 /*
3004 Is this the best place for components deinit? It may be changed when new
3005 dependencies are discovered, possibly being divided into separate points
3006 where all dependencies are still ok.
3007 */
3008 8457 log_error_stage_set(LOG_ERROR_STAGE_SHUTTING_DOWN);
3009 8457 log_builtins_error_stack(LOG_ERROR_SERVICES_DEFAULT, false, nullptr);
3010 #ifdef HAVE_PSI_THREAD_INTERFACE
3011
6/6
✓ Branch 0 taken 8438 times.
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 8226 times.
✓ Branch 3 taken 212 times.
✓ Branch 4 taken 8226 times.
✓ Branch 5 taken 231 times.
8457 if (!is_help_or_validate_option() && !opt_initialize) {
3012 8226 unregister_pfs_notification_service();
3013 8226 unregister_pfs_resource_group_service();
3014 }
3015 #endif
3016 8457 deinit_tls_psi_keys();
3017 8457 deinitialize_manifest_file_components();
3018 8457 component_infrastructure_deinit();
3019 /*
3020 component unregister_variable() api depends on system_variable_hash.
3021 component_infrastructure_deinit() interns calls the deinit function
3022 of components which are loaded, and the deinit functions can have
3023 the component system unregister_ variable() api's, hence we need
3024 to call the sys_var_end() after component_infrastructure_deinit()
3025 */
3026 8457 sys_var_end();
3027 8457 free_status_vars();
3028
3029 8457 finish_client_errs();
3030 8457 deinit_errmessage(); // finish server errs
3031
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8457 times.
8457 DBUG_PRINT("quit", ("Error messages freed"));
3032
3033
2/2
✓ Branch 0 taken 8385 times.
✓ Branch 1 taken 72 times.
8457 if (have_statement_timeout == SHOW_OPTION_YES) my_timer_deinitialize();
3034
3035 8457 have_statement_timeout = SHOW_OPTION_DISABLED;
3036
3037 8457 persisted_variables_cache.cleanup();
3038
3039 8457 udf_deinit_globals();
3040 /*
3041 The following lines may never be executed as the main thread may have
3042 killed us
3043 */
3044
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8457 times.
8457 DBUG_PRINT("quit", ("done with cleanup"));
3045 } /* clean_up */
3046
3047 8468 static void clean_up_mutexes() {
3048 8468 mysql_mutex_destroy(&LOCK_log_throttle_qni);
3049 8468 mysql_mutex_destroy(&LOCK_status);
3050 8468 mysql_mutex_destroy(&LOCK_manager);
3051 8468 mysql_mutex_destroy(&LOCK_crypt);
3052 8468 mysql_mutex_destroy(&LOCK_user_conn);
3053 8468 mysql_rwlock_destroy(&LOCK_sys_init_connect);
3054 8468 mysql_rwlock_destroy(&LOCK_sys_init_replica);
3055 8468 mysql_mutex_destroy(&LOCK_global_system_variables);
3056 8468 mysql_rwlock_destroy(&LOCK_system_variables_hash);
3057 8468 mysql_mutex_destroy(&LOCK_uuid_generator);
3058 8468 mysql_mutex_destroy(&LOCK_sql_rand);
3059 8468 mysql_mutex_destroy(&LOCK_prepared_stmt_count);
3060 8468 mysql_mutex_destroy(&LOCK_replica_list);
3061 8468 mysql_mutex_destroy(&LOCK_sql_replica_skip_counter);
3062 8468 mysql_mutex_destroy(&LOCK_replica_net_timeout);
3063 8468 mysql_mutex_destroy(&LOCK_replica_trans_dep_tracker);
3064 8468 mysql_mutex_destroy(&LOCK_error_messages);
3065 8468 mysql_mutex_destroy(&LOCK_default_password_lifetime);
3066 8468 mysql_mutex_destroy(&LOCK_mandatory_roles);
3067 8468 mysql_mutex_destroy(&LOCK_server_started);
3068 8468 mysql_cond_destroy(&COND_server_started);
3069 8468 mysql_mutex_destroy(&LOCK_reset_gtid_table);
3070 8468 mysql_mutex_destroy(&LOCK_compress_gtid_table);
3071 8468 mysql_cond_destroy(&COND_compress_gtid_table);
3072 8468 mysql_mutex_destroy(&LOCK_collect_instance_log);
3073 8468 mysql_mutex_destroy(&LOCK_password_history);
3074 8468 mysql_mutex_destroy(&LOCK_password_reuse_interval);
3075 8468 mysql_cond_destroy(&COND_manager);
3076 #ifdef _WIN32
3077 mysql_cond_destroy(&COND_handler_count);
3078 mysql_mutex_destroy(&LOCK_handler_count);
3079 mysql_rwlock_destroy(&LOCK_named_pipe_full_access_group);
3080 #endif
3081 #ifndef _WIN32
3082 8468 mysql_cond_destroy(&COND_socket_listener_active);
3083 8468 mysql_mutex_destroy(&LOCK_socket_listener_active);
3084 8468 mysql_cond_destroy(&COND_start_signal_handler);
3085 8468 mysql_mutex_destroy(&LOCK_start_signal_handler);
3086 #endif
3087 8468 mysql_mutex_destroy(&LOCK_keyring_operations);
3088 8468 mysql_mutex_destroy(&LOCK_tls_ctx_options);
3089 8468 mysql_mutex_destroy(&LOCK_rotate_binlog_master_key);
3090 8468 mysql_mutex_destroy(&LOCK_global_user_client_stats);
3091 8468 mysql_mutex_destroy(&LOCK_global_table_stats);
3092 8468 mysql_mutex_destroy(&LOCK_global_index_stats);
3093 8468 mysql_rwlock_destroy(&LOCK_consistent_snapshot);
3094 8468 mysql_mutex_destroy(&LOCK_admin_tls_ctx_options);
3095 8468 mysql_mutex_destroy(&LOCK_partial_revokes);
3096 8468 mysql_mutex_destroy(&LOCK_authentication_policy);
3097 8468 mysql_mutex_destroy(&LOCK_global_conn_mem_limit);
3098 #ifdef WITH_WSREP
3099 8468 mysql_mutex_destroy(&LOCK_wsrep_ready);
3100 8468 mysql_cond_destroy(&COND_wsrep_ready);
3101 8468 mysql_mutex_destroy(&LOCK_wsrep_sst);
3102 8468 mysql_cond_destroy(&COND_wsrep_sst);
3103 8468 mysql_mutex_destroy(&LOCK_wsrep_sst_init);
3104 8468 mysql_cond_destroy(&COND_wsrep_sst_init);
3105 8468 mysql_mutex_destroy(&LOCK_wsrep_replaying);
3106 8468 mysql_cond_destroy(&COND_wsrep_replaying);
3107 8468 mysql_mutex_destroy(&LOCK_wsrep_slave_threads);
3108 8468 mysql_cond_destroy(&COND_wsrep_slave_threads);
3109 8468 mysql_mutex_destroy(&LOCK_wsrep_cluster_config);
3110 8468 mysql_mutex_destroy(&LOCK_wsrep_desync);
3111 8468 mysql_mutex_destroy(&LOCK_wsrep_group_commit);
3112 8468 mysql_cond_destroy(&COND_wsrep_group_commit);
3113 8468 mysql_mutex_destroy(&LOCK_wsrep_SR_pool);
3114 8468 mysql_mutex_destroy(&LOCK_wsrep_SR_store);
3115 8468 mysql_mutex_destroy(&LOCK_wsrep_alter_tablespace);
3116 #endif /* WITH_WSREP */
3117 8468 }
3118
3119 /****************************************************************************
3120 ** Init IP and UNIX socket
3121 ****************************************************************************/
3122
3123 /* Initialise proxy protocol. */
3124 9243 static void set_proxy() {
3125
2/2
✓ Branch 0 taken 335 times.
✓ Branch 1 taken 8908 times.
9247 if (opt_disable_networking) return;
3126
3127 struct st_vio_network net;
3128
3129 /* Check for special case '*'. */
3130
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 8904 times.
8908 if (strcmp(my_proxy_protocol_networks, "*") == 0) {
3131 4 memset(&net, 0, sizeof(net));
3132 4 net.family = AF_INET;
3133 4 vio_proxy_protocol_add(net);
3134 4 net.family = AF_INET6;
3135 4 vio_proxy_protocol_add(net);
3136 4 return;
3137 }
3138
3139 8904 const char *p = my_proxy_protocol_networks;
3140
3141 while (1) {
3142 /* jump spaces. */
3143
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8921 times.
8921 while (*p == ' ') p++;
3144
2/2
✓ Branch 0 taken 8893 times.
✓ Branch 1 taken 28 times.
8922 if (*p == '\0') break;
3145 28 const char *start = p;
3146
3147 /* look for separator */
3148
7/8
✓ Branch 0 taken 423 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 403 times.
✓ Branch 3 taken 20 times.
✓ Branch 4 taken 403 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 397 times.
✓ Branch 7 taken 6 times.
425 while (*p != ',' && *p != '/' && *p != ' ' && *p != '\0') p++;
3149
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 27 times.
28 if (p - start > INET6_ADDRSTRLEN) {
3150
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 sql_print_error(
3151 "Too long network in 'proxy_protocol_networks' "
3152 "directive.");
3153
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
1 unireg_abort(1);
3154 }
3155 char buffer[INET6_ADDRSTRLEN + 1 + 3 + 1];
3156 27 memcpy(buffer, start, p - start);
3157 27 buffer[p - start] = '\0';
3158
3159 /* Try to convert to ipv4. */
3160
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 17 times.
27 if (inet_pton(AF_INET, buffer, &net.addr.in)) net.family = AF_INET;
3161
3162 /* Try to convert to ipv6. */
3163
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
17 else if (inet_pton(AF_INET6, buffer, &net.addr.in6))
3164 12 net.family = AF_INET6;
3165
3166 else {
3167
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 sql_print_error(
3168 "Bad network '%s' in 'proxy_protocol_networks' "
3169 "directive.",
3170 buffer);
3171
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
5 unireg_abort(1);
3172 }
3173
3174 /* Look for network. */
3175 unsigned bits;
3176
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 2 times.
22 if (*p == '/') {
3177
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 19 times.
20 if (!my_isdigit(&my_charset_bin, *++p)) {
3178
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 sql_print_error(
3179 "Missing network prefix in 'proxy_protocol_networks' "
3180 "directive.");
3181
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
1 unireg_abort(1);
3182 }
3183 19 start = p;
3184 19 bits = 0;
3185
4/4
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 39 times.
✓ Branch 3 taken 1 times.
58 while (my_isdigit(&my_charset_bin, *p) && p - start < 3)
3186 39 bits = bits * 10 + *p++ - '0';
3187
3188 /* Check bits value. */
3189
4/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 7 times.
19 if (net.family == AF_INET && bits > 32) {
3190
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 sql_print_error(
3191 "Bad IPv4 mask in 'proxy_protocol_networks' "
3192 "directive.");
3193
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
1 unireg_abort(1);
3194 }
3195
4/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 10 times.
18 if (net.family == AF_INET6 && bits > 128) {
3196
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 sql_print_error(
3197 "Bad IPv6 mask in 'proxy_protocol_networks' "
3198 "directive.");
3199
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
1 unireg_abort(1);
3200 }
3201 } else {
3202
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (net.family == AF_INET)
3203 1 bits = 32;
3204 else {
3205
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert(net.family == AF_INET6);
3206 1 bits = 128;
3207 }
3208 }
3209
3210 /* Build binary mask. */
3211
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 11 times.
19 if (net.family == AF_INET) {
3212 /* Process IPv4 mask. */
3213
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
8 if (bits == 0)
3214 2 net.mask.in.s_addr = 0x00000000;
3215
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
6 else if (bits == 32)
3216 2 net.mask.in.s_addr = 0xffffffff;
3217 else
3218 4 net.mask.in.s_addr = ~((0x80000000 >> (bits - 1)) - 1);
3219 8 net.mask.in.s_addr = htonl(net.mask.in.s_addr);
3220
3221 /* Apply mask */
3222 8 struct in_addr check = net.addr.in;
3223 8 check.s_addr &= net.mask.in.s_addr;
3224
3225 /* Check network. */
3226
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
8 if (check.s_addr != net.addr.in.s_addr)
3227
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 sql_print_warning(
3228 "The network mask hides a part of the address for "
3229 "'%s/%d' in 'proxy_protocol_networks' directive.",
3230 buffer, bits);
3231 } else {
3232 /* Process IPv6 mask */
3233 11 memset(&net.mask.in6, 0, sizeof(net.mask.in6));
3234
4/4
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 9 times.
11 if (bits > 0 && bits < 32) {
3235 1 net.mask.in6.s6_addr32[0] = ~((0x80000000 >> (bits - 1)) - 1);
3236
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9 times.
10 } else if (bits == 32) {
3237 1 net.mask.in6.s6_addr32[0] = 0xffffffff;
3238
4/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 6 times.
9 } else if (bits > 32 && bits <= 64) {
3239 2 net.mask.in6.s6_addr32[0] = 0xffffffff;
3240 2 net.mask.in6.s6_addr32[1] =
3241
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 (bits == 64) ? 0xffffffff : ~((0x80000000 >> (bits - 32 - 1)) - 1);
3242
4/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 3 times.
7 } else if (bits > 64 && bits <= 96) {
3243 3 net.mask.in6.s6_addr32[0] = 0xffffffff;
3244 3 net.mask.in6.s6_addr32[1] = 0xffffffff;
3245 3 net.mask.in6.s6_addr32[2] =
3246
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 (bits == 96) ? 0xffffffff : ~((0x80000000 >> (bits - 64 - 1)) - 1);
3247
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 } else if (bits > 96) {
3248
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 assert(bits <= 128);
3249 3 net.mask.in6.s6_addr32[0] = 0xffffffff;
3250 3 net.mask.in6.s6_addr32[1] = 0xffffffff;
3251 3 net.mask.in6.s6_addr32[2] = 0xffffffff;
3252 3 net.mask.in6.s6_addr32[3] =
3253
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 (bits == 128) ? 0xffffffff : ~((0x80000000 >> (bits - 96 - 1)) - 1);
3254 }
3255
3256 11 net.mask.in6.s6_addr32[0] = htonl(net.mask.in6.s6_addr32[0]);
3257 11 net.mask.in6.s6_addr32[1] = htonl(net.mask.in6.s6_addr32[1]);
3258 11 net.mask.in6.s6_addr32[2] = htonl(net.mask.in6.s6_addr32[2]);
3259 11 net.mask.in6.s6_addr32[3] = htonl(net.mask.in6.s6_addr32[3]);
3260
3261 /* Apply mask */
3262 11 struct in6_addr check = net.addr.in6;
3263 11 check.s6_addr32[0] &= net.mask.in6.s6_addr32[0];
3264 11 check.s6_addr32[1] &= net.mask.in6.s6_addr32[1];
3265 11 check.s6_addr32[2] &= net.mask.in6.s6_addr32[2];
3266 11 check.s6_addr32[3] &= net.mask.in6.s6_addr32[3];
3267
3268 /* Check network. */
3269
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 3 times.
11 if (memcmp(check.s6_addr, net.addr.in6.s6_addr, 16)) {
3270
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 sql_print_warning(
3271 "The network mask hides a part of the address for "
3272 "'%s/%d' in 'proxy_protocol_networks' directive.",
3273 buffer, bits);
3274 }
3275 }
3276
3277
4/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 17 times.
19 if (*p != '\0' && *p != ',') {
3278
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 sql_print_error("Bad syntax in 'proxy_protocol_networks' directive.");
3279
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
1 unireg_abort(1);
3280 }
3281
3282 /* add network. */
3283 18 vio_proxy_protocol_add(net);
3284
3285 /* stop the parsing. */
3286
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 17 times.
18 if (*p == '\0') break;
3287 17 p++;
3288 17 }
3289 }
3290
3291 10213 static void set_ports() {
3292 char *env;
3293
2/2
✓ Branch 0 taken 656 times.
✓ Branch 1 taken 9557 times.
10213 if (!mysqld_port &&
3294
2/2
✓ Branch 0 taken 87 times.
✓ Branch 1 taken 569 times.
656 !opt_disable_networking) { // Get port if not from commandline
3295 87 mysqld_port = MYSQL_PORT;
3296
3297 /*
3298 if builder specifically requested a default port, use that
3299 (even if it coincides with our factory default).
3300 only if they didn't do we check /etc/services (and, failing
3301 on that, fall back to the factory default of 3306).
3302 either default can be overridden by the environment variable
3303 MYSQL_TCP_PORT, which in turn can be overridden with command
3304 line options.
3305 */
3306
3307 #if MYSQL_PORT_DEFAULT == 0
3308 struct servent *serv_ptr;
3309
1/2
✓ Branch 0 taken 87 times.
✗ Branch 1 not taken.
87 if ((serv_ptr = getservbyname("mysql", "tcp")))
3310 87 mysqld_port = ntohs((u_short)serv_ptr->s_port); /* purecov: inspected */
3311 #endif
3312
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 87 times.
87 if ((env = getenv("MYSQL_TCP_PORT")))
3313 mysqld_port = (uint)atoi(env); /* purecov: inspected */
3314 }
3315
2/2
✓ Branch 0 taken 269 times.
✓ Branch 1 taken 9944 times.
10213 if (!mysqld_unix_port) {
3316 #ifdef _WIN32
3317 mysqld_unix_port = (char *)MYSQL_NAMEDPIPE;
3318 #else
3319 269 mysqld_unix_port = MYSQL_UNIX_ADDR;
3320 #endif
3321
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 269 times.
269 if ((env = getenv("MYSQL_UNIX_PORT")))
3322 mysqld_unix_port = env; /* purecov: inspected */
3323 }
3324 10213 }
3325
3326 #if !defined(_WIN32)
3327 /* Change to run as another user if started with --user */
3328
3329 9774 static PasswdValue check_user(const char *user) {
3330 9774 uid_t user_id = geteuid();
3331
3332 PasswdValue tmp_user_info =
3333
3/4
✓ Branch 0 taken 9768 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
9774 (user == nullptr ? PasswdValue{} : my_getpwnam(user));
3334
3335 // Don't bother if we aren't superuser
3336
1/2
✓ Branch 0 taken 9774 times.
✗ Branch 1 not taken.
9774 if (user_id) {
3337
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 9768 times.
9774 if (user) {
3338 /* Don't give a warning, if real user is same as given with --user */
3339
4/6
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 if ((tmp_user_info.IsVoid() || user_id != tmp_user_info.pw_uid))
3340
8/16
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 6 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 6 times.
✗ Branch 15 not taken.
6 LogErr(WARNING_LEVEL, ER_USER_REQUIRES_ROOT);
3341 }
3342 9774 return PasswdValue{};
3343 }
3344 assert(user_id == 0); // we are running as root
3345
3346 if (!user) {
3347 if (!opt_initialize && !is_help_or_validate_option()) {
3348 LogErr(ERROR_LEVEL, ER_REALLY_RUN_AS_ROOT);
3349 unireg_abort(MYSQLD_ABORT_EXIT);
3350 }
3351 return PasswdValue{};
3352 }
3353 /* purecov: begin tested */
3354 if (!strcmp(user, "root"))
3355 return PasswdValue{}; // Avoid problem with dynamic libraries
3356
3357 if (tmp_user_info.IsVoid()) {
3358 // Allow a numeric uid to be used
3359 const char *pos;
3360 for (pos = user; my_isdigit(mysqld_charset, *pos); pos++)
3361 ;
3362 if (*pos) // Not numeric id
3363 goto err;
3364
3365 tmp_user_info = my_getpwuid(atoi(user));
3366 if (tmp_user_info.IsVoid()) goto err;
3367 }
3368 return tmp_user_info;
3369 /* purecov: end */
3370
3371 err:
3372 LogErr(ERROR_LEVEL, ER_USER_WHAT_USER, user);
3373 unireg_abort(MYSQLD_ABORT_EXIT);
3374
3375 return PasswdValue{};
3376 9774 }
3377
3378 namespace mysqld_funcs_unit_test {
3379 7 PasswdValue check_user_drv(const char *user) { return check_user(user); }
3380 } // namespace mysqld_funcs_unit_test
3381
3382 static void set_user(const char *user, const PasswdValue &user_info_arg) {
3383 /* purecov: begin tested */
3384 assert(user_info_arg.IsVoid() == false);
3385 #ifdef HAVE_INITGROUPS
3386 initgroups(user, user_info_arg.pw_gid);
3387 #endif
3388 if (setgid(user_info_arg.pw_gid) == -1) {
3389 LogErr(ERROR_LEVEL, ER_FAIL_SETGID, strerror(errno));
3390 unireg_abort(MYSQLD_ABORT_EXIT);
3391 }
3392 if (setuid(user_info_arg.pw_uid) == -1) {
3393 LogErr(ERROR_LEVEL, ER_FAIL_SETUID, strerror(errno));
3394 unireg_abort(MYSQLD_ABORT_EXIT);
3395 }
3396
3397 #ifdef HAVE_SYS_PRCTL_H
3398 if (test_flags & TEST_CORE_ON_SIGNAL) {
3399 /* inform kernel that process is dumpable */
3400 (void)prctl(PR_SET_DUMPABLE, 1);
3401 }
3402 #endif
3403
3404 /* purecov: end */
3405 }
3406
3407 static void set_effective_user(const PasswdValue &user_info_arg) {
3408 assert(user_info_arg.IsVoid() == false);
3409 if (setregid((gid_t)-1, user_info_arg.pw_gid) == -1) {
3410 LogErr(ERROR_LEVEL, ER_FAIL_SETREGID, strerror(errno));
3411 unireg_abort(MYSQLD_ABORT_EXIT);
3412 }
3413 if (setreuid((uid_t)-1, user_info_arg.pw_uid) == -1) {
3414 LogErr(ERROR_LEVEL, ER_FAIL_SETREUID, strerror(errno));
3415 unireg_abort(MYSQLD_ABORT_EXIT);
3416 }
3417 }
3418
3419 /** Change root user if started with @c --chroot . */
3420 static void set_root(const char *path) {
3421 if (chroot(path) == -1) {
3422 LogErr(ERROR_LEVEL, ER_FAIL_CHROOT, strerror(errno));
3423 unireg_abort(MYSQLD_ABORT_EXIT);
3424 }
3425 my_setwd("/", MYF(0));
3426 }
3427 #endif // !_WIN32
3428
3429 /**
3430 Check that an address value is a wildcard IP value,
3431 that is it has either the value 0.0.0.0 for IPv4 or the value ::1 in
3432 case IPv6, or has the specially treated symbol * as its value.
3433
3434 @param address_value Address value to check
3435 @param address_length Address length
3436
3437 @return true in case the address value is a wildcard value, else false.
3438 */
3439 8609 bool check_address_is_wildcard(const char *address_value,
3440 size_t address_length) {
3441 return
3442 // Wildcard is not allowed in case a comma separated list of
3443 // addresses is specified
3444 8609 native_strncasecmp(address_value, MY_BIND_ALL_ADDRESSES,
3445
2/2
✓ Branch 0 taken 73 times.
✓ Branch 1 taken 6 times.
79 address_length) == 0 ||
3446 // The specially treated address :: is not allowed in case
3447 // a comma separated list of addresses is specified
3448 79 native_strncasecmp(address_value, ipv6_all_addresses, address_length) ==
3449
4/4
✓ Branch 0 taken 79 times.
✓ Branch 1 taken 8530 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 68 times.
8688 0 ||
3450 // The specially treated address 0.0.0.0 is not allowed in case
3451 // a comma separated list of addresses is specified
3452 73 native_strncasecmp(address_value, ipv4_all_addresses, address_length) ==
3453 8609 0;
3454 }
3455
3456 /**
3457 Take a string representing host or ip address followed by
3458 optional delimiter '/' and namespace name and put address part
3459 and namespace part into corresponding output parameters.
3460
3461 @param begin_address_value start of a string containing an address value
3462 @param end_address_value pointer to an end of string containing
3463 an address value. Has the value nullptr in case
3464 address value not continue
3465 @param [out] address_value address value extracted from address string
3466 @param [out] network_namespace network namespace extracted from
3467 the address string value if any
3468
3469 @return false on success, true on address format error
3470 */
3471 9266 static bool parse_address_string(const char *begin_address_value,
3472 const char *end_address_value,
3473 std::string *address_value,
3474 std::string *network_namespace) {
3475 9266 const char *namespace_separator = strchr(begin_address_value, '/');
3476
3477
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9266 times.
9266 if (namespace_separator != nullptr) {
3478 if (begin_address_value == namespace_separator)
3479 /*
3480 Parse error: there is no character before '/',
3481 that is missed address value
3482 */
3483 return true;
3484
3485 if (namespace_separator < end_address_value) {
3486 if (end_address_value - namespace_separator == 1)
3487 /*
3488 Parse error: there is no character immediately after '/',
3489 that is missed namespace name.
3490 */
3491 return true;
3492
3493 /*
3494 Found namespace delimiter. Extract namespace and address values
3495 */
3496 *address_value = std::string(begin_address_value, namespace_separator);
3497 *network_namespace =
3498 std::string(namespace_separator + 1, end_address_value);
3499 } else if (end_address_value != nullptr)
3500 /*
3501 This branch corresponds to the case when namespace separator is located
3502 after the last character of the address subvalue being processed.
3503 For example, if the following string '192.168.1.1,172.1.1.1/red'
3504 passed into the function create_bind_address_info_from_string(),
3505 then during handling of the address 192.168.1.1 search of '/'
3506 will return a position after the end of the sub string 192.168.1.1
3507 (in the next sub string 172.1.1.1/red) that should be ignored.
3508 */
3509 *address_value = std::string(begin_address_value, end_address_value);
3510 else {
3511 /*
3512 This branch corresponds to the case when namespace separator is located
3513 at the last part of address values. For example,
3514 this branch is executed during handling of the following value
3515 192.168.1.1,::1,::1/greeen for the option --bind-address.
3516 */
3517 *address_value = std::string(begin_address_value, namespace_separator);
3518 *network_namespace = std::string(namespace_separator + 1);
3519 if (*(namespace_separator + 1) == 0)
3520 /*
3521 Parse error: there is no character immediately
3522 after '/' - a namespace name missed.
3523 */
3524 return true;
3525 }
3526 } else {
3527 /*
3528 Regular address without network namespace found.
3529 */
3530 *address_value = end_address_value != nullptr
3531
8/14
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9257 times.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9257 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 9257 times.
✓ Branch 7 taken 9 times.
✓ Branch 8 taken 9 times.
✓ Branch 9 taken 9257 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
18532 ? std::string(begin_address_value, end_address_value)
3532 9266 : std::string(begin_address_value);
3533 }
3534
3535 9266 return false;
3536 }
3537
3538 /**
3539 Parse a value of address sub string with checking of address string format,
3540 extract address part and namespace part of the address value, and store
3541 their values into the argument valid_bind_addresses.
3542
3543 @return false on success, true on address format error
3544 */
3545 9234 static bool create_bind_address_info_from_string(
3546 const char *begin_address_value, const char *end_address_value,
3547 std::list<Bind_address_info> *valid_bind_addresses) {
3548 9234 Bind_address_info bind_address_info;
3549 9234 std::string address_value, network_namespace;
3550
3551
2/4
✓ Branch 0 taken 9234 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9234 times.
9234 if (parse_address_string(begin_address_value, end_address_value,
3552 &address_value, &network_namespace))
3553 return true;
3554
3555
1/2
✓ Branch 0 taken 9234 times.
✗ Branch 1 not taken.
9234 if (network_namespace.empty())
3556
1/2
✓ Branch 0 taken 9234 times.
✗ Branch 1 not taken.
9234 bind_address_info = Bind_address_info(address_value);
3557 else {
3558 /*
3559 Wildcard value is not allowed in case network namespace specified
3560 for address value in the option bind-address.
3561 */
3562 if (check_address_is_wildcard(address_value.c_str(),
3563 address_value.length())) {
3564 LogErr(ERROR_LEVEL,
3565 ER_NETWORK_NAMESPACE_NOT_ALLOWED_FOR_WILDCARD_ADDRESS);
3566 return true;
3567 }
3568
3569 bind_address_info = Bind_address_info(address_value, network_namespace);
3570 }
3571
3572
1/2
✓ Branch 0 taken 9234 times.
✗ Branch 1 not taken.
9234 valid_bind_addresses->emplace_back(bind_address_info);
3573
3574 9234 return false;
3575 9234 }
3576
3577 /**
3578 Check acceptable value(s) of parameter bind-address
3579
3580 @param bind_address Value of the parameter bind-address
3581 @param[out] valid_bind_addresses List of addresses to listen and their
3582 corresponding network namespaces if set.
3583
3584 @return false on success, true on failure
3585 */
3586 9233 static bool check_bind_address_has_valid_value(
3587 const char *bind_address,
3588 std::list<Bind_address_info> *valid_bind_addresses) {
3589
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9231 times.
9233 if (strlen(bind_address) == 0)
3590 // Empty value for bind_address is an error
3591 2 return true;
3592
3593 9231 const char *comma_separator = strchr(bind_address, ',');
3594 9231 const char *begin_of_value = bind_address;
3595 9231 const bool multiple_bind_addresses = (comma_separator != nullptr);
3596
3597
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9230 times.
9231 if (comma_separator == begin_of_value)
3598 // Return an error if a value of bind_address begins with comma
3599 1 return true;
3600
3601
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 9228 times.
9238 while (comma_separator != nullptr) {
3602 10 Bind_address_info bind_address_info;
3603 10 std::string address_value, network_namespace;
3604 /*
3605 Wildcard value is not allowed in case multi-addresses value specified
3606 for the option bind-address.
3607 */
3608
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9 times.
10 if (check_address_is_wildcard(begin_of_value,
3609
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 comma_separator - begin_of_value)) {
3610
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(ERROR_LEVEL, ER_WILDCARD_NOT_ALLOWED_FOR_MULTIADDRESS_BIND);
3611
3612 1 return true;
3613 }
3614
3615
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if (create_bind_address_info_from_string(begin_of_value, comma_separator,
3616 valid_bind_addresses))
3617 return true;
3618
3619 9 begin_of_value = comma_separator + 1;
3620 9 comma_separator = strchr(begin_of_value, ',');
3621
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8 times.
9 if (comma_separator == begin_of_value)
3622 // Return an error if a value of bind_address has two adjacent commas
3623 1 return true;
3624
6/6
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 2 times.
14 }
3625
3626 /*
3627 Wildcard value is not allowed in case multi-addresses value specified
3628 for the option bind-address.
3629 */
3630
4/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 9223 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 9225 times.
9233 if (multiple_bind_addresses &&
3631
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
5 (check_address_is_wildcard(begin_of_value, strlen(begin_of_value)) ||
3632
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 strlen(begin_of_value) == 0))
3633 3 return true;
3634
3635
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9225 times.
9225 if (create_bind_address_info_from_string(begin_of_value, comma_separator,
3636 valid_bind_addresses))
3637 return true;
3638
3639 9225 return false;
3640 }
3641
3642 /**
3643 Check acceptable value(s) of the parameter admin-address
3644
3645 @param admin_bind_addr_str Value of the parameter admin-address
3646 @param[out] admin_address_info List of addresses to listen and their
3647 corresponding network namespaces if set.
3648
3649 @return false on success, true on failure
3650 */
3651 32 static bool check_admin_address_has_valid_value(
3652 const char *admin_bind_addr_str, Bind_address_info *admin_address_info) {
3653 32 std::string address_value, network_namespace;
3654
3655
2/4
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 32 times.
32 if (parse_address_string(admin_bind_addr_str, nullptr, &address_value,
3656 &network_namespace))
3657 return true;
3658
3659
3/4
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 29 times.
32 if (check_address_is_wildcard(address_value.c_str(),
3660 address_value.length())) {
3661
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!network_namespace.empty())
3662 LogErr(ERROR_LEVEL,
3663 ER_NETWORK_NAMESPACE_NOT_ALLOWED_FOR_WILDCARD_ADDRESS);
3664
3665 3 return true;
3666 }
3667
3668
1/2
✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
29 if (network_namespace.empty())
3669
1/2
✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
29 *admin_address_info = Bind_address_info(address_value);
3670 else
3671 *admin_address_info = Bind_address_info(address_value, network_namespace);
3672
3673 29 return false;
3674 32 }
3675
3676 9445 static bool network_init(void) {
3677
2/2
✓ Branch 0 taken 202 times.
✓ Branch 1 taken 9243 times.
9445 if (opt_initialize) return false;
3678
3679
1/2
✓ Branch 0 taken 9233 times.
✗ Branch 1 not taken.
9243 set_proxy();
3680 #ifdef HAVE_SYS_UN_H
3681
2/4
✓ Branch 0 taken 9233 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9233 times.
✗ Branch 3 not taken.
9233 std::string const unix_sock_name(mysqld_unix_port ? mysqld_unix_port : "");
3682 #else
3683 std::string const unix_sock_name("");
3684 #endif
3685
3686 9233 std::list<Bind_address_info> bind_addresses_info;
3687
3688
5/8
✓ Branch 0 taken 335 times.
✓ Branch 1 taken 8898 times.
✓ Branch 2 taken 335 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 335 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 9233 times.
✗ Branch 7 not taken.
9233 if (!opt_disable_networking || unix_sock_name != "") {
3689
3/4
✓ Branch 0 taken 9233 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 9225 times.
18466 if (my_bind_addr_str != nullptr &&
3690
3/4
✓ Branch 0 taken 9233 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 9225 times.
9233 check_bind_address_has_valid_value(my_bind_addr_str,
3691 &bind_addresses_info)) {
3692
8/16
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 8 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 8 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 8 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 8 times.
✗ Branch 15 not taken.
8 LogErr(ERROR_LEVEL, ER_INVALID_VALUE_OF_BIND_ADDRESSES, my_bind_addr_str);
3693 15 return true;
3694 }
3695
3696 9225 Bind_address_info admin_address_info;
3697
2/2
✓ Branch 0 taken 8890 times.
✓ Branch 1 taken 335 times.
9225 if (!opt_disable_networking) {
3698
4/4
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 8858 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 8887 times.
8922 if (my_admin_bind_addr_str != nullptr &&
3699
3/4
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 29 times.
32 check_admin_address_has_valid_value(my_admin_bind_addr_str,
3700 &admin_address_info)) {
3701
8/16
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
3 LogErr(ERROR_LEVEL, ER_INVALID_ADMIN_ADDRESS, my_admin_bind_addr_str);
3702 3 return true;
3703 }
3704 /*
3705 Port 0 is interpreted by implementations of TCP protocol
3706 as a hint to find a first free port value to use and bind to it.
3707 On the other hand, the option mysqld_admin_port can be assigned
3708 the value 0 if a user specified a value that is out of allowable
3709 range of values. Therefore, to avoid a case when an operating
3710 system binds admin interface to am arbitrary selected port value,
3711 set it explicitly to the value MYSQL_ADMIN_PORT in case it has value 0.
3712 */
3713
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8886 times.
8887 if (mysqld_admin_port == 0) mysqld_admin_port = MYSQL_ADMIN_PORT;
3714 }
3715 Mysqld_socket_listener *mysqld_socket_listener = new (std::nothrow)
3716 Mysqld_socket_listener(bind_addresses_info, mysqld_port,
3717 admin_address_info, mysqld_admin_port,
3718 9222 admin_address_info.address.empty()
3719
2/2
✓ Branch 0 taken 9193 times.
✓ Branch 1 taken 29 times.
9222 ? false
3720 : listen_admin_interface_in_separate_thread,
3721
3/6
✓ Branch 0 taken 9222 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9222 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9222 times.
✗ Branch 5 not taken.
9222 back_log, mysqld_port_timeout, unix_sock_name);
3722
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9222 times.
9222 if (mysqld_socket_listener == nullptr) return true;
3723
3724 9222 mysqld_socket_acceptor = new (std::nothrow)
3725
1/2
✓ Branch 0 taken 9222 times.
✗ Branch 1 not taken.
9222 Connection_acceptor<Mysqld_socket_listener>(mysqld_socket_listener);
3726
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9222 times.
9222 if (mysqld_socket_acceptor == nullptr) {
3727 delete mysqld_socket_listener;
3728 mysqld_socket_listener = nullptr;
3729 return true;
3730 }
3731
3732
3/4
✓ Branch 0 taken 9222 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 9218 times.
9222 if (mysqld_socket_acceptor->init_connection_acceptor())
3733 4 return true; // mysqld_socket_acceptor would be freed in unireg_abort.
3734
3735
2/2
✓ Branch 0 taken 6625 times.
✓ Branch 1 taken 2593 times.
9218 if (report_port == 0) report_port = mysqld_port;
3736
3737
3/4
✓ Branch 0 taken 8883 times.
✓ Branch 1 taken 335 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8883 times.
9218 if (!opt_disable_networking) assert(report_port != 0);
3738
2/2
✓ Branch 0 taken 9218 times.
✓ Branch 1 taken 7 times.
9225 }
3739 #ifdef _WIN32
3740 // Create named pipe
3741 if (opt_enable_named_pipe) {
3742 std::string pipe_name = mysqld_unix_port ? mysqld_unix_port : "";
3743
3744 named_pipe_listener = new (std::nothrow) Named_pipe_listener(&pipe_name);
3745 if (named_pipe_listener == NULL) return true;
3746
3747 named_pipe_acceptor = new (std::nothrow)
3748 Connection_acceptor<Named_pipe_listener>(named_pipe_listener);
3749 if (named_pipe_acceptor == NULL) {
3750 delete named_pipe_listener;
3751 named_pipe_listener = NULL;
3752 return true;
3753 }
3754
3755 if (named_pipe_acceptor->init_connection_acceptor())
3756 return true; // named_pipe_acceptor would be freed in unireg_abort.
3757 }
3758
3759 // Setup shared_memory acceptor
3760 if (opt_enable_shared_memory) {
3761 std::string shared_mem_base_name =
3762 shared_memory_base_name ? shared_memory_base_name : "";
3763
3764 Shared_mem_listener *shared_mem_listener =
3765 new (std::nothrow) Shared_mem_listener(&shared_mem_base_name);
3766 if (shared_mem_listener == NULL) return true;
3767
3768 shared_mem_acceptor = new (std::nothrow)
3769 Connection_acceptor<Shared_mem_listener>(shared_mem_listener);
3770 if (shared_mem_acceptor == NULL) {
3771 delete shared_mem_listener;
3772 shared_mem_listener = NULL;
3773 return true;
3774 }
3775
3776 if (shared_mem_acceptor->init_connection_acceptor())
3777 return true; // shared_mem_acceptor would be freed in unireg_abort.
3778 }
3779 #endif // _WIN32
3780 9218 return false;
3781 9233 }
3782
3783 #ifdef _WIN32
3784 static uint handler_count = 0;
3785
3786 static inline void decrement_handler_count() {
3787 mysql_mutex_lock(&LOCK_handler_count);
3788 handler_count--;
3789 mysql_cond_signal(&COND_handler_count);
3790 mysql_mutex_unlock(&LOCK_handler_count);
3791 }
3792
3793 extern "C" void *socket_conn_event_handler(void *arg) {
3794 my_thread_init();
3795
3796 Connection_acceptor<Mysqld_socket_listener> *conn_acceptor =
3797 static_cast<Connection_acceptor<Mysqld_socket_listener> *>(arg);
3798 conn_acceptor->connection_event_loop();
3799
3800 decrement_handler_count();
3801 my_thread_end();
3802 return 0;
3803 }
3804
3805 extern "C" void *named_pipe_conn_event_handler(void *arg) {
3806 my_thread_init();
3807
3808 Connection_acceptor<Named_pipe_listener> *conn_acceptor =
3809 static_cast<Connection_acceptor<Named_pipe_listener> *>(arg);
3810 conn_acceptor->connection_event_loop();
3811
3812 decrement_handler_count();
3813 my_thread_end();
3814 return 0;
3815 }
3816
3817 extern "C" void *shared_mem_conn_event_handler(void *arg) {
3818 my_thread_init();
3819
3820 Connection_acceptor<Shared_mem_listener> *conn_acceptor =
3821 static_cast<Connection_acceptor<Shared_mem_listener> *>(arg);
3822 conn_acceptor->connection_event_loop();
3823
3824 decrement_handler_count();
3825 my_thread_end();
3826 return 0;
3827 }
3828
3829 void setup_conn_event_handler_threads() {
3830 my_thread_handle hThread;
3831
3832 DBUG_TRACE;
3833
3834 if ((!have_tcpip || opt_disable_networking) && !opt_enable_shared_memory &&
3835 !opt_enable_named_pipe) {
3836 LogErr(ERROR_LEVEL, ER_WIN_LISTEN_BUT_HOW);
3837 unireg_abort(MYSQLD_ABORT_EXIT); // Will not return
3838 }
3839
3840 mysql_mutex_lock(&LOCK_handler_count);
3841 handler_count = 0;
3842
3843 if (opt_enable_named_pipe) {
3844 int error = mysql_thread_create(
3845 key_thread_handle_con_namedpipes, &hThread, &connection_attrib,
3846 named_pipe_conn_event_handler, named_pipe_acceptor);
3847 if (!error)
3848 handler_count++;
3849 else
3850 LogErr(WARNING_LEVEL, ER_CANT_CREATE_NAMED_PIPES_THREAD, error);
3851 }
3852
3853 if (have_tcpip && !opt_disable_networking) {
3854 int error = mysql_thread_create(
3855 key_thread_handle_con_sockets, &hThread, &connection_attrib,
3856 socket_conn_event_handler, mysqld_socket_acceptor);
3857 if (!error)
3858 handler_count++;
3859 else
3860 LogErr(WARNING_LEVEL, ER_CANT_CREATE_TCPIP_THREAD, error);
3861 }
3862
3863 if (opt_enable_shared_memory) {
3864 int error = mysql_thread_create(
3865 key_thread_handle_con_sharedmem, &hThread, &connection_attrib,
3866 shared_mem_conn_event_handler, shared_mem_acceptor);
3867 if (!error)
3868 handler_count++;
3869 else
3870 LogErr(WARNING_LEVEL, ER_CANT_CREATE_SHM_THREAD, error);
3871 }
3872
3873 // Block until all connection listener threads have exited.
3874 while (handler_count > 0)
3875 mysql_cond_wait(&COND_handler_count, &LOCK_handler_count);
3876 mysql_mutex_unlock(&LOCK_handler_count);
3877 }
3878
3879 /*
3880 On Windows, we use native SetConsoleCtrlHandler for handle events like Ctrl-C
3881 with graceful shutdown.
3882 Also, we do not use signal(), but SetUnhandledExceptionFilter instead - as it
3883 provides possibility to pass the exception to just-in-time debugger, collect
3884 dumps and potentially also the exception and thread context used to output
3885 callstack.
3886 */
3887
3888 static BOOL WINAPI console_event_handler(DWORD type) {
3889 DBUG_TRACE;
3890 if (type == CTRL_C_EVENT) {
3891 /*
3892 Do not shutdown before startup is finished and shutdown
3893 thread is initialized. Otherwise there is a race condition
3894 between main thread doing initialization and CTRL-C thread doing
3895 cleanup, which can result into crash.
3896 */
3897 if (hEventShutdown)
3898 kill_mysql();
3899 else
3900 LogErr(WARNING_LEVEL, ER_NOT_RIGHT_NOW);
3901 return true;
3902 }
3903 return false;
3904 }
3905
3906 #ifdef DEBUG_UNHANDLED_EXCEPTION_FILTER
3907 #define DEBUGGER_ATTACH_TIMEOUT 120
3908 /*
3909 Wait for debugger to attach and break into debugger. If debugger is not
3910 attached, resume after timeout.
3911 */
3912 static void wait_for_debugger(int timeout_sec) {
3913 if (!IsDebuggerPresent()) {
3914 int i;
3915 printf("Waiting for debugger to attach, pid=%u\n", GetCurrentProcessId());
3916 fflush(stdout);
3917 for (i = 0; i < timeout_sec; i++) {
3918 Sleep(1000);
3919 if (IsDebuggerPresent()) {
3920 /* Break into debugger */
3921 __debugbreak();
3922 return;
3923 }
3924 }
3925 printf("pid=%u, debugger not attached after %d seconds, resuming\n",
3926 GetCurrentProcessId(), timeout_sec);
3927 fflush(stdout);
3928 }
3929 }
3930 #endif /* DEBUG_UNHANDLED_EXCEPTION_FILTER */
3931
3932 LONG WINAPI my_unhandler_exception_filter(EXCEPTION_POINTERS *ex_pointers) {
3933 static BOOL first_time = true;
3934 if (!first_time) {
3935 /*
3936 This routine can be called twice, typically
3937 when detaching in JIT debugger.
3938 Return EXCEPTION_EXECUTE_HANDLER to terminate process.
3939 */
3940 return EXCEPTION_EXECUTE_HANDLER;
3941 }
3942 first_time = false;
3943 #ifdef DEBUG_UNHANDLED_EXCEPTION_FILTER
3944 /*
3945 Unfortunately there is no clean way to debug unhandled exception filters,
3946 as debugger does not stop there(also documented in MSDN)
3947 To overcome, one could put a MessageBox, but this will not work in service.
3948 Better solution is to print error message and sleep some minutes
3949 until debugger is attached
3950 */
3951 wait_for_debugger(DEBUGGER_ATTACH_TIMEOUT);
3952 #endif /* DEBUG_UNHANDLED_EXCEPTION_FILTER */
3953 __try {
3954 my_set_exception_pointers(ex_pointers);
3955 handle_fatal_signal(ex_pointers->ExceptionRecord->ExceptionCode);
3956 } __except (EXCEPTION_EXECUTE_HANDLER) {
3957 DWORD written;
3958 const char msg[] = "Got exception in exception handler!\n";
3959 WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), msg, sizeof(msg) - 1, &written,
3960 NULL);
3961 }
3962 /*
3963 Return EXCEPTION_CONTINUE_SEARCH to give JIT debugger
3964 (drwtsn32 or vsjitdebugger) possibility to attach,
3965 if JIT debugger is configured.
3966 Windows Error reporting might generate a dump here.
3967 */
3968 return EXCEPTION_CONTINUE_SEARCH;
3969 }
3970
3971 void my_init_signals() {
3972 if (opt_console) SetConsoleCtrlHandler(console_event_handler, true);
3973
3974 /* Avoid MessageBox()es*/
3975 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
3976 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
3977 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
3978 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
3979 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
3980 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
3981
3982 /*
3983 Do not use SEM_NOGPFAULTERRORBOX in the following SetErrorMode (),
3984 because it would prevent JIT debugger and Windows error reporting
3985 from working. We need WER or JIT-debugging, since our own unhandled
3986 exception filter is not guaranteed to work in all situation
3987 (like heap corruption or stack overflow)
3988 */
3989 SetErrorMode(SetErrorMode(0) | SEM_FAILCRITICALERRORS |
3990 SEM_NOOPENFILEERRORBOX);
3991 SetUnhandledExceptionFilter(my_unhandler_exception_filter);
3992 }
3993
3994 #else // !_WIN32
3995
3996 extern "C" {
3997 25922 static void empty_signal_handler(int sig [[maybe_unused]]) {}
3998 }
3999
4000 9824 void my_init_signals() {
4001
1/2
✓ Branch 0 taken 9824 times.
✗ Branch 1 not taken.
9824 DBUG_TRACE;
4002 struct sigaction sa;
4003 9824 (void)sigemptyset(&sa.sa_mask);
4004
4005
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 9804 times.
9824 if (!(test_flags & TEST_NO_STACKTRACE) ||
4006
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 (test_flags & TEST_CORE_ON_SIGNAL)) {
4007 #ifdef HAVE_STACKTRACE
4008
1/2
✓ Branch 0 taken 9804 times.
✗ Branch 1 not taken.
9804 my_init_stacktrace();
4009 #endif
4010
4011
2/2
✓ Branch 0 taken 8998 times.
✓ Branch 1 taken 806 times.
9804 if (test_flags & TEST_CORE_ON_SIGNAL) {
4012 // Change limits so that we will get a core file.
4013 struct rlimit rl;
4014 8998 rl.rlim_cur = rl.rlim_max = RLIM_INFINITY;
4015
1/18
✗ Branch 0 not taken.
✓ Branch 1 taken 8998 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
8998 if (setrlimit(RLIMIT_CORE, &rl)) LogErr(WARNING_LEVEL, ER_CORE_VALUES);
4016 }
4017
4018 /*
4019 SA_RESETHAND resets handler action to default when entering handler.
4020 SA_NODEFER allows receiving the same signal during handler.
4021 E.g. SIGABRT during our signal handler will dump core (default action).
4022 */
4023 9804 sa.sa_flags = SA_RESETHAND | SA_NODEFER;
4024 9804 sa.sa_handler = handle_fatal_signal;
4025 // Treat these as fatal and handle them.
4026 9804 sigaction(SIGABRT, &sa, nullptr);
4027 9804 sigaction(SIGFPE, &sa, nullptr);
4028 // Handle these as well, except for ASAN/UBSAN builds:
4029 // we let sanitizer runtime handle them instead.
4030 #if defined(HANDLE_FATAL_SIGNALS)
4031 9804 sigaction(SIGBUS, &sa, nullptr);
4032 9804 sigaction(SIGILL, &sa, nullptr);
4033 9804 sigaction(SIGSEGV, &sa, nullptr);
4034 #endif
4035 }
4036
4037 // Ignore SIGPIPE
4038 9824 sa.sa_flags = 0;
4039 9824 sa.sa_handler = SIG_IGN;
4040 9824 (void)sigaction(SIGPIPE, &sa, nullptr);
4041
4042 // SIGALRM is used to interrupt the socket listener.
4043 9824 sa.sa_handler = empty_signal_handler;
4044 9824 (void)sigaction(SIGALRM, &sa, nullptr);
4045
4046 // Fix signals if ignored by parents (can happen on Mac OS X).
4047 9824 sa.sa_handler = SIG_DFL;
4048 9824 (void)sigaction(SIGTERM, &sa, nullptr);
4049 9824 (void)sigaction(SIGHUP, &sa, nullptr);
4050 9824 (void)sigaction(SIGUSR1, &sa, nullptr);
4051
4052 9824 (void)sigemptyset(&mysqld_signal_mask);
4053 /*
4054 Block SIGQUIT, SIGHUP, SIGTERM, SIGUSR1 and SIGUSR2.
4055 The signal handler thread does sigwait() on these.
4056 */
4057 9824 (void)sigaddset(&mysqld_signal_mask, SIGQUIT);
4058 9824 (void)sigaddset(&mysqld_signal_mask, SIGHUP);
4059 9824 (void)sigaddset(&mysqld_signal_mask, SIGTERM);
4060 9824 (void)sigaddset(&mysqld_signal_mask, SIGTSTP);
4061 9824 (void)sigaddset(&mysqld_signal_mask, SIGUSR1);
4062 9824 (void)sigaddset(&mysqld_signal_mask, SIGUSR2);
4063 /*
4064 Block SIGINT unless debugging to prevent Ctrl+C from causing
4065 unclean shutdown of the server.
4066 */
4067
2/2
✓ Branch 0 taken 9811 times.
✓ Branch 1 taken 13 times.
9824 if (!(test_flags & TEST_SIGINT)) (void)sigaddset(&mysqld_signal_mask, SIGINT);
4068 9824 pthread_sigmask(SIG_SETMASK, &mysqld_signal_mask, nullptr);
4069 9824 }
4070
4071 9379 static void start_signal_handler() {
4072 int error;
4073 my_thread_attr_t thr_attr;
4074
1/2
✓ Branch 0 taken 9379 times.
✗ Branch 1 not taken.
9379 DBUG_TRACE;
4075
4076 9379 (void)my_thread_attr_init(&thr_attr);
4077 9379 (void)pthread_attr_setscope(&thr_attr, PTHREAD_SCOPE_SYSTEM);
4078 9379 (void)my_thread_attr_setdetachstate(&thr_attr, MY_THREAD_CREATE_JOINABLE);
4079
4080 9379 size_t guardize = 0;
4081 9379 (void)pthread_attr_getguardsize(&thr_attr, &guardize);
4082 #if defined(__ia64__) || defined(__ia64)
4083 /*
4084 Peculiar things with ia64 platforms - it seems we only have half the
4085 stack size in reality, so we have to double it here
4086 */
4087 guardize = my_thread_stack_size;
4088 #endif
4089
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9379 times.
9379 if (0 !=
4090 9379 my_thread_attr_setstacksize(&thr_attr, my_thread_stack_size + guardize)) {
4091 assert(false);
4092 }
4093
4094 /*
4095 Set main_thread_id so that SIGTERM/SIGQUIT/SIGKILL/SIGUSR2 can interrupt
4096 the socket listener successfully.
4097 */
4098 9379 main_thread_id = my_thread_self();
4099
4100
1/2
✓ Branch 0 taken 9379 times.
✗ Branch 1 not taken.
9379 mysql_mutex_lock(&LOCK_start_signal_handler);
4101
2/4
✓ Branch 0 taken 9379 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9379 times.
9379 if ((error = mysql_thread_create(key_thread_signal_hand, &signal_thread_id,
4102 &thr_attr, signal_hand, nullptr))) {
4103 LogErr(ERROR_LEVEL, ER_CANT_CREATE_INTERRUPT_THREAD, error, errno);
4104 flush_error_log_messages();
4105 exit(MYSQLD_ABORT_EXIT);
4106 }
4107
1/2
✓ Branch 0 taken 9379 times.
✗ Branch 1 not taken.
9379 mysql_cond_wait(&COND_start_signal_handler, &LOCK_start_signal_handler);
4108
1/2
✓ Branch 0 taken 9379 times.
✗ Branch 1 not taken.
9379 mysql_mutex_unlock(&LOCK_start_signal_handler);
4109
4110 9379 (void)my_thread_attr_destroy(&thr_attr);
4111 9379 }
4112
4113 /** This thread handles SIGTERM, SIGQUIT, SIGHUP, SIGUSR1 and SIGUSR2 signals.
4114 */
4115 /* ARGSUSED */
4116 9379 extern "C" void *signal_hand(void *arg [[maybe_unused]]) {
4117
1/2
✓ Branch 0 taken 9379 times.
✗ Branch 1 not taken.
9379 my_thread_init();
4118
4119 sigset_t set;
4120 9379 (void)sigemptyset(&set);
4121 9379 (void)sigaddset(&set, SIGTERM);
4122 9379 (void)sigaddset(&set, SIGQUIT);
4123 9379 (void)sigaddset(&set, SIGHUP);
4124 9379 (void)sigaddset(&set, SIGUSR1);
4125 9379 (void)sigaddset(&set, SIGUSR2);
4126
4127 /*
4128 Signal to start_signal_handler that we are ready.
4129 This works by waiting for start_signal_handler to free mutex,
4130 after which we signal it that we are ready.
4131 */
4132
1/2
✓ Branch 0 taken 9379 times.
✗ Branch 1 not taken.
9379 mysql_mutex_lock(&LOCK_start_signal_handler);
4133
1/2
✓ Branch 0 taken 9379 times.
✗ Branch 1 not taken.
9379 mysql_cond_broadcast(&COND_start_signal_handler);
4134
1/2
✓ Branch 0 taken 9379 times.
✗ Branch 1 not taken.
9379 mysql_mutex_unlock(&LOCK_start_signal_handler);
4135
4136 /*
4137 Wait until that all server components have been successfully initialized.
4138 This step is mandatory since signal processing can be done safely only when
4139 all server components have been initialized.
4140 */
4141
1/2
✓ Branch 0 taken 9379 times.
✗ Branch 1 not taken.
9379 server_components_init_wait();
4142 for (;;) {
4143 9390 int sig = 0;
4144 int rc;
4145 bool error;
4146 #ifdef __APPLE__
4147 while ((rc = sigwait(&set, &sig)) == EINTR) {
4148 }
4149 error = rc != 0;
4150 #else
4151 siginfo_t sig_info;
4152
6/8
✓ Branch 0 taken 8099 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 35 times.
✓ Branch 3 taken 8064 times.
✓ Branch 4 taken 35 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 35 times.
✓ Branch 7 taken 8064 times.
9425 while ((rc = sigwaitinfo(&set, &sig_info)) == -1 && errno == EINTR) {
4153 }
4154 8064 error = rc == -1;
4155
1/2
✓ Branch 0 taken 8064 times.
✗ Branch 1 not taken.
8064 if (!error) sig = sig_info.si_signo;
4156 #endif // __APPLE__
4157
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8064 times.
8064 if (error)
4158 sql_print_error(
4159 "Fatal error in signal handling thread. sigwait/sigwaitinfo returned "
4160 "error %d\n. Exiting signal handler "
4161 "thread.",
4162 errno);
4163
4164
2/4
✓ Branch 0 taken 8064 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8064 times.
8064 if (error || cleanup_done) {
4165 my_thread_end();
4166 my_thread_exit(nullptr); // Safety
4167 return nullptr; // Avoid compiler warnings
4168 }
4169
4/5
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 8002 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
8064 switch (sig) {
4170 51 case SIGUSR2:
4171 51 signal_hand_thr_exit_code = MYSQLD_RESTART_EXIT;
4172 #ifndef __APPLE__ // Mac OS doesn't have sigwaitinfo.
4173 // Log a note if mysqld is restarted via kill command.
4174
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
51 if (sig_info.si_pid != getpid()) {
4175 sql_print_information(
4176 "Received signal SIGUSR2."
4177 " Restarting mysqld (Version %s)",
4178 server_version);
4179 }
4180 #endif // __APPLE__
4181 [[fallthrough]];
4182 case SIGTERM:
4183 case SIGQUIT:
4184 #ifndef __APPLE__ // Mac OS doesn't have sigwaitinfo.
4185
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 8050 times.
8053 if (sig_info.si_pid != getpid())
4186
8/16
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
3 LogErr(SYSTEM_LEVEL, ER_SERVER_SHUTDOWN_INFO, "<via user signal>",
4187 server_version, MYSQL_COMPILATION_COMMENT_SERVER);
4188 #else
4189 LogErr(SYSTEM_LEVEL, ER_SERVER_SHUTDOWN_INFO, "<via user signal>",
4190 server_version, MYSQL_COMPILATION_COMMENT_SERVER);
4191 #endif // __APPLE__
4192 #ifdef WITH_WSREP
4193
3/4
✓ Branch 0 taken 431 times.
✓ Branch 1 taken 7622 times.
✓ Branch 2 taken 431 times.
✗ Branch 3 not taken.
8053 if (WSREP_ON) {
4194 431 pxc_maint_mode = PXC_MAINT_MODE_SHUTDOWN;
4195
10/22
✓ Branch 0 taken 431 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 431 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 431 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 431 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 431 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 431 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 431 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 431 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 431 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 431 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
431 WSREP_INFO(
4196 "Received shutdown signal. Will sleep for %lu secs"
4197 " before initiating shutdown. pxc_maint_mode switched"
4198 " to SHUTDOWN",
4199 pxc_maint_transition_period);
4200
1/2
✓ Branch 0 taken 431 times.
✗ Branch 1 not taken.
431 sleep(pxc_maint_transition_period);
4201 }
4202 #endif /* WITH_WSREP */
4203 // Switch to the file log message processing.
4204
3/4
✓ Branch 0 taken 7744 times.
✓ Branch 1 taken 309 times.
✓ Branch 2 taken 8053 times.
✗ Branch 3 not taken.
8053 query_logger.set_handlers((log_output_options != LOG_NONE) ? LOG_FILE
4205 : LOG_NONE);
4206
3/8
✓ Branch 0 taken 8053 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8053 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 8053 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
8053 DBUG_PRINT("info",
4207 ("Got signal: %d connection_events_loop_aborted: %d", sig,
4208 connection_events_loop_aborted()));
4209
1/2
✓ Branch 0 taken 8053 times.
✗ Branch 1 not taken.
8053 if (!connection_events_loop_aborted()) {
4210 // Mark abort for threads.
4211 8053 set_connection_events_loop_aborted(true);
4212 #ifdef HAVE_PSI_THREAD_INTERFACE
4213 // Delete the instrumentation for the signal thread.
4214
1/2
✓ Branch 0 taken 8053 times.
✗ Branch 1 not taken.
8053 PSI_THREAD_CALL(delete_current_thread)();
4215 #endif /* HAVE_PSI_THREAD_INTERFACE */
4216 /*
4217 Kill the socket listener.
4218 The main thread will then set socket_listener_active= false,
4219 and wait for us to finish all the cleanup below.
4220 */
4221
1/2
✓ Branch 0 taken 8053 times.
✗ Branch 1 not taken.
8053 mysql_mutex_lock(&LOCK_socket_listener_active);
4222
2/2
✓ Branch 0 taken 7851 times.
✓ Branch 1 taken 8053 times.
15904 while (socket_listener_active) {
4223
3/8
✓ Branch 0 taken 7851 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7851 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 7851 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
7851 DBUG_PRINT("info", ("Killing socket listener"));
4224
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7851 times.
7851 if (pthread_kill(main_thread_id, SIGALRM)) {
4225 assert(false);
4226 break;
4227 }
4228
1/2
✓ Branch 0 taken 7851 times.
✗ Branch 1 not taken.
7851 mysql_cond_wait(&COND_socket_listener_active,
4229 &LOCK_socket_listener_active);
4230 }
4231
1/2
✓ Branch 0 taken 8053 times.
✗ Branch 1 not taken.
8053 mysql_mutex_unlock(&LOCK_socket_listener_active);
4232
4233 #ifdef WITH_WSREP
4234 /* Stop wsrep threads in case they are running. */
4235
3/4
✓ Branch 0 taken 431 times.
✓ Branch 1 taken 7622 times.
✓ Branch 2 taken 431 times.
✗ Branch 3 not taken.
8053 if (wsrep_running_threads > 0) wsrep_shutdown_replication();
4236 #endif /* WITH_WSREP */
4237
4238
1/2
✓ Branch 0 taken 8048 times.
✗ Branch 1 not taken.
8053 close_connections();
4239
4240 #ifdef WITH_WSREP
4241
4/6
✓ Branch 0 taken 431 times.
✓ Branch 1 taken 7617 times.
✓ Branch 2 taken 431 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 431 times.
✗ Branch 5 not taken.
8048 if (WSREP_ON) wsrep_deinit();
4242 #endif /* WITH_WSREP */
4243 }
4244
1/2
✓ Branch 0 taken 8048 times.
✗ Branch 1 not taken.
8048 my_thread_end();
4245 8048 my_thread_exit(nullptr);
4246 return nullptr; // Avoid compiler warnings
4247 break;
4248 4 case SIGHUP:
4249
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (!connection_events_loop_aborted()) {
4250 int not_used;
4251
5/8
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
4 DBUG_EXECUTE_IF("simulate_sighup_print_status", {
4252 printf("\nStatus information:\n\n");
4253 fflush(stdout);
4254 });
4255
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 handle_reload_request(
4256 nullptr,
4257 (REFRESH_LOG | REFRESH_TABLES | REFRESH_FAST | REFRESH_GRANT |
4258 REFRESH_THREADS | REFRESH_HOSTS),
4259 nullptr, &not_used); // Flush logs
4260 // Re-enable query logs after the options were reloaded.
4261
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 query_logger.set_handlers(log_output_options);
4262 }
4263 4 break;
4264 7 case SIGUSR1:
4265
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if (!connection_events_loop_aborted()) {
4266 int not_used;
4267
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 handle_reload_request(
4268 nullptr,
4269 (REFRESH_ERROR_LOG | /**< Rotate only the error log */
4270 REFRESH_GENERAL_LOG | /**< Flush the general log */
4271 REFRESH_SLOW_LOG), /**< Flush the slow query log */
4272 nullptr, &not_used); // Flush logs
4273 // Re-enable query logs after the options were reloaded.
4274
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 query_logger.set_handlers(log_output_options);
4275 }
4276 7 break;
4277 default:
4278 break; /* purecov: tested */
4279 }
4280 11 }
4281 return nullptr; /* purecov: deadcode */
4282 }
4283
4284 #endif // !_WIN32
4285
4286 /**
4287 All global error messages are sent here where the first one is stored
4288 for the client.
4289 */
4290 /* ARGSUSED */
4291 extern "C" void my_message_sql(uint error, const char *str, myf MyFlags);
4292
4293 2336504 void my_message_sql(uint error, const char *str, myf MyFlags) {
4294
1/2
✓ Branch 0 taken 2336508 times.
✗ Branch 1 not taken.
2336504 THD *thd = current_thd;
4295
1/2
✓ Branch 0 taken 2336522 times.
✗ Branch 1 not taken.
2336508 DBUG_TRACE;
4296
5/8
✓ Branch 0 taken 2336519 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2336520 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✓ Branch 5 taken 2336504 times.
✓ Branch 6 taken 16 times.
✗ Branch 7 not taken.
2336522 DBUG_PRINT("error", ("error: %u message: '%s'", error, str));
4297
4298
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2336520 times.
2336520 assert(str != nullptr);
4299 /*
4300 An error should have a valid error number (!= 0), so it can be caught
4301 in stored procedures by SQL exception handlers.
4302 Calling my_error() with error == 0 is a bug.
4303 Remaining known places to fix:
4304 - storage/myisam/mi_create.c, my_printf_error()
4305 TODO:
4306 assert(error != 0);
4307 */
4308
4309
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2336519 times.
2336520 if (error == 0) {
4310 /* At least, prevent new abuse ... */
4311
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert(strncmp(str, "MyISAM table", 12) == 0);
4312 1 error = ER_UNKNOWN_ERROR;
4313 }
4314
4315 /* Caller wishes to inform client, and one is attached. */
4316
2/2
✓ Branch 0 taken 2336211 times.
✓ Branch 1 taken 309 times.
2336520 if (thd) {
4317 2336211 (void)thd->raise_condition(error, nullptr, Sql_condition::SL_ERROR, str,
4318
1/2
✓ Branch 0 taken 2336220 times.
✗ Branch 1 not taken.
2336211 MyFlags & ME_FATALERROR);
4319
4320 /*
4321 Now for an argument check.
4322 We're asserting after rather than before raising the
4323 condition to make the culprit easier to track down.
4324
4325 Messages intended for the error-log are in the range
4326 starting at ER_SERVER_RANGE_START (error_code 10,000);
4327 messages intended for sending to a client are in the
4328 range below ER_SERVER_RANGE_START. If a message is to
4329 be sent to both a client and the error log, it must
4330 be added twice (once in each range), and two separate
4331 calls (e.g. my_error() and LogErr()) must be added to
4332 the code.
4333
4334 Only error-codes from the client range should be seen
4335 in this if(). If your patch asserts here, one of two
4336 things probably happened:
4337
4338 - You added a new message to messages_to_error_log.txt:
4339 The message was added to the server range, but code
4340 was added that tries to send the message to a client
4341 (my_error(), push_warning_printf(), etc.).
4342
4343 => Move the new message to messages_to_clients.txt.
4344 The copied message should be added at the end of
4345 the range for the lowest server version you're adding
4346 the message to.
4347 Rebuild the server; rerun your test.
4348
4349 - You used an existing message:
4350 The existing message is intended for use with
4351 the error-log (it appears in messages_to_error_log.txt),
4352 but the new code tries to send it to a client (my_error(),
4353 push_warning_printf(), etc.).
4354
4355 => Copy the existing message to messages_to_clients.txt.
4356 - The copied message should be added at the end of
4357 the range for the lowest server version you're adding
4358 the message to.
4359 - The copied message will need its own symbol;
4360 if in doubt, call the copy of ER_EXAMPLE_MESSAGE
4361 ER_DA_EXAMPLE_MESSAGE (as this version is for use
4362 with the diagnostics area).
4363 Then make sure that your new code references
4364 this new symbol when it sends the message
4365 to a client.
4366 Rebuild the server; rerun your test.
4367
4368 We'll assert this here (rather than in raise_condition) as
4369 SQL's SIGNAL command also calls raise_condition, and SIGNAL
4370 is currently allowed to set any error-code (regardless of
4371 range). SIGNALing an error-code from the error-log range
4372 will not result in writing to that log to prevent abuse.
4373 */
4374
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2336220 times.
2336220 assert(error < ER_SERVER_RANGE_START);
4375 }
4376
4377 /* When simulating OOM, skip writing to error log to avoid mtr errors */
4378
3/4
✓ Branch 0 taken 2336520 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 2336508 times.
2336529 DBUG_EXECUTE_IF("simulate_out_of_memory", return;);
4379
4380 /*
4381 Caller wishes to send to both the client and the error-log.
4382 This is legacy behaviour that is no longer legal as errors flagged
4383 to a client and those sent to the error-log are in different
4384 numeric ranges now. If you own code that does this, see about
4385 updating it by splitting it into two calls, one sending status
4386 to the client, the other sending it to the error-log using
4387 LogErr() and friends.
4388 */
4389
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2336506 times.
2336508 if (MyFlags & ME_ERRORLOG) {
4390 /*
4391 We've removed most uses of ME_ERRORLOG in the server.
4392 This leaves three possible cases, in which we'll rewrite
4393 the error-code from one in the client-range to one in
4394 the error-log range here:
4395
4396 - EE_OUTOFMEMORY: Correct to ER_SERVER_OUT_OF_RESOURCES so
4397 mysys can remain logger-agnostic.
4398
4399 - HA_* range: Correct to catch-all ER_SERVER_HANDLER_ERROR.
4400
4401 - otherwise: Flag as using info from the diagnostics area
4402 (ER_ERROR_INFO_FROM_DA). This is a failsafe;
4403 if your code triggers it, your code is probably
4404 wrong.
4405 */
4406
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if ((error == EE_OUTOFMEMORY) || (error == HA_ERR_OUT_OF_MEM))
4407 error = ER_SERVER_OUT_OF_RESOURCES;
4408
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 else if (error <= HA_ERR_LAST)
4409 2 error = ER_SERVER_HANDLER_ERROR;
4410
4411
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (error < ER_SERVER_RANGE_START)
4412 LogEvent()
4413 .type(LOG_TYPE_ERROR)
4414 .prio(ERROR_LEVEL)
4415 .errcode(ER_ERROR_INFO_FROM_DA)
4416 .lookup(ER_ERROR_INFO_FROM_DA, error, str);
4417 else
4418
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
4 LogEvent()
4419
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 .type(LOG_TYPE_ERROR)
4420
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 .prio(ERROR_LEVEL)
4421
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 .errcode(error)
4422
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 .verbatim(str);
4423
4424 /*
4425 This is no longer supported behaviour except for the cases
4426 outlined above, so flag anything else in debug builds!
4427 (We're bailing after rather than before printing to make the
4428 culprit easier to track down.)
4429 */
4430
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 assert((error == ER_FEATURE_NOT_AVAILABLE) ||
4431 (error >= ER_SERVER_RANGE_START));
4432 }
4433
4434 /*
4435 Caller wishes to send to client, but none is attached, so we send
4436 to error-log instead.
4437 */
4438
2/2
✓ Branch 0 taken 303 times.
✓ Branch 1 taken 2336203 times.
2336506 else if (!thd) {
4439
1/2
✓ Branch 0 taken 303 times.
✗ Branch 1 not taken.
606 LogEvent()
4440
1/2
✓ Branch 0 taken 303 times.
✗ Branch 1 not taken.
303 .type(LOG_TYPE_ERROR)
4441
1/2
✓ Branch 0 taken 303 times.
✗ Branch 1 not taken.
303 .subsys(LOG_SUBSYSTEM_TAG)
4442
1/2
✓ Branch 0 taken 303 times.
✗ Branch 1 not taken.
303 .prio(ERROR_LEVEL)
4443
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 303 times.
✓ Branch 2 taken 303 times.
✗ Branch 3 not taken.
303 .errcode((error < ER_SERVER_RANGE_START)
4444 ? ER_SERVER_NO_SESSION_TO_SEND_TO
4445 : error)
4446
1/2
✓ Branch 0 taken 303 times.
✗ Branch 1 not taken.
303 .lookup(ER_SERVER_NO_SESSION_TO_SEND_TO, error, str);
4447 }
4448
2/2
✓ Branch 0 taken 2336506 times.
✓ Branch 1 taken 12 times.
2336520 }
4449
4450 extern "C" void *my_str_malloc_mysqld(size_t size);
4451 extern "C" void my_str_free_mysqld(void *ptr);
4452 extern "C" void *my_str_realloc_mysqld(void *ptr, size_t size);
4453
4454 13 void *my_str_malloc_mysqld(size_t size) {
4455 13 return my_malloc(key_memory_my_str_malloc, size, MYF(MY_FAE));
4456 }
4457
4458 13 void my_str_free_mysqld(void *ptr) { my_free(ptr); }
4459
4460 void *my_str_realloc_mysqld(void *ptr, size_t size) {
4461 return my_realloc(key_memory_my_str_malloc, ptr, size, MYF(MY_FAE));
4462 }
4463
4464 const char *load_default_groups[] = {
4465 #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
4466 "mysql_cluster",
4467 #endif
4468 "mysqld", "server", MYSQL_BASE_VERSION, nullptr, nullptr};
4469
4470 #if defined(_WIN32)
4471 static const int load_default_groups_sz =
4472 sizeof(load_default_groups) / sizeof(load_default_groups[0]);
4473 #endif
4474
4475 /**
4476 This function is used to check for stack overrun for pathological
4477 cases of regular expressions and 'like' expressions.
4478 The call to current_thd is quite expensive, so we try to avoid it
4479 for the normal cases.
4480 The size of each stack frame for the wildcmp() routines is ~128 bytes,
4481 so checking *every* recursive call is not necessary.
4482 */
4483 extern "C" {
4484 167465833 static int check_enough_stack_size(int recurse_level) {
4485 uchar stack_top;
4486
1/2
✓ Branch 0 taken 167465833 times.
✗ Branch 1 not taken.
167465833 if (recurse_level % 16 != 0) return 0;
4487
4488 THD *my_thd = current_thd;
4489 if (my_thd != nullptr)
4490 return check_stack_overrun(my_thd, STACK_MIN_SIZE * 4, &stack_top);
4491 return 0;
4492 }
4493 } // extern "C"
4494
4495 SHOW_VAR com_status_vars[] = {
4496 {"admin_commands", (char *)offsetof(System_status_var, com_other),
4497 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4498 {"assign_to_keycache",
4499 (char *)offsetof(System_status_var,
4500 com_stat[(uint)SQLCOM_ASSIGN_TO_KEYCACHE]),
4501 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4502 {"alter_db",
4503 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_ALTER_DB]),
4504 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4505 {"alter_event",
4506 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_ALTER_EVENT]),
4507 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4508 {"alter_function",
4509 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_ALTER_FUNCTION]),
4510 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4511 {"alter_instance",
4512 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_ALTER_INSTANCE]),
4513 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4514 {"alter_procedure",
4515 (char *)offsetof(System_status_var,
4516 com_stat[(uint)SQLCOM_ALTER_PROCEDURE]),
4517 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4518 {"alter_resource_group",
4519 (char *)offsetof(System_status_var,
4520 com_stat[(uint)SQLCOM_ALTER_RESOURCE_GROUP]),
4521 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4522 {"alter_server",
4523 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_ALTER_SERVER]),
4524 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4525 {"alter_table",
4526 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_ALTER_TABLE]),
4527 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4528 {"alter_tablespace",
4529 (char *)offsetof(System_status_var,
4530 com_stat[(uint)SQLCOM_ALTER_TABLESPACE]),
4531 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4532 {"alter_user",
4533 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_ALTER_USER]),
4534 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4535 {"alter_user_default_role",
4536 (char *)offsetof(System_status_var,
4537 com_stat[(uint)SQLCOM_ALTER_USER_DEFAULT_ROLE]),
4538 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4539 {"analyze",
4540 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_ANALYZE]),
4541 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4542 {"begin", (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_BEGIN]),
4543 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4544 {"binlog",
4545 (char *)offsetof(System_status_var,
4546 com_stat[(uint)SQLCOM_BINLOG_BASE64_EVENT]),
4547 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4548 {"call_procedure",
4549 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CALL]),
4550 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4551 {"change_db",
4552 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CHANGE_DB]),
4553 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4554 {"change_master",
4555 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CHANGE_MASTER]),
4556 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4557 {"change_repl_filter",
4558 (char *)offsetof(System_status_var,
4559 com_stat[(uint)SQLCOM_CHANGE_REPLICATION_FILTER]),
4560 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4561 {"change_replication_source",
4562 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CHANGE_MASTER]),
4563 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4564 {"check", (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CHECK]),
4565 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4566 {"checksum",
4567 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CHECKSUM]),
4568 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4569 {"clone", (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CLONE]),
4570 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4571 {"commit",
4572 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_COMMIT]),
4573 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4574 {"create_compression_dictionary",
4575 (char *)offsetof(System_status_var,
4576 com_stat[(uint)SQLCOM_CREATE_COMPRESSION_DICTIONARY]),
4577 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4578 {"create_db",
4579 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CREATE_DB]),
4580 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4581 {"create_event",
4582 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CREATE_EVENT]),
4583 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4584 {"create_function",
4585 (char *)offsetof(System_status_var,
4586 com_stat[(uint)SQLCOM_CREATE_SPFUNCTION]),
4587 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4588 {"create_index",
4589 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CREATE_INDEX]),
4590 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4591 {"create_procedure",
4592 (char *)offsetof(System_status_var,
4593 com_stat[(uint)SQLCOM_CREATE_PROCEDURE]),
4594 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4595 {"create_role",
4596 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CREATE_ROLE]),
4597 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4598 {"create_server",
4599 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CREATE_SERVER]),
4600 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4601 {"create_table",
4602 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CREATE_TABLE]),
4603 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4604 {"create_resource_group",
4605 (char *)offsetof(System_status_var,
4606 com_stat[(uint)SQLCOM_CREATE_RESOURCE_GROUP]),
4607 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4608 {"create_trigger",
4609 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CREATE_TRIGGER]),
4610 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4611 {"create_udf",
4612 (char *)offsetof(System_status_var,
4613 com_stat[(uint)SQLCOM_CREATE_FUNCTION]),
4614 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4615 {"create_user",
4616 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CREATE_USER]),
4617 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4618 {"create_view",
4619 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CREATE_VIEW]),
4620 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4621 {"create_spatial_reference_system",
4622 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_CREATE_SRS]),
4623 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4624 {"dealloc_sql",
4625 (char *)offsetof(System_status_var,
4626 com_stat[(uint)SQLCOM_DEALLOCATE_PREPARE]),
4627 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4628 {"delete",
4629 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_DELETE]),
4630 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4631 {"delete_multi",
4632 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_DELETE_MULTI]),
4633 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4634 {"do", (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_DO]),
4635 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4636 {"drop_compression_dictionary",
4637 (char *)offsetof(System_status_var,
4638 com_stat[(uint)SQLCOM_DROP_COMPRESSION_DICTIONARY]),
4639 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4640 {"drop_db",
4641 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_DROP_DB]),
4642 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4643 {"drop_event",
4644 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_DROP_EVENT]),
4645 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4646 {"drop_function",
4647 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_DROP_FUNCTION]),
4648 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4649 {"drop_index",
4650 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_DROP_INDEX]),
4651 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4652 {"drop_procedure",
4653 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_DROP_PROCEDURE]),
4654 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4655 {"drop_resource_group",
4656 (char *)offsetof(System_status_var,
4657 com_stat[(uint)SQLCOM_DROP_RESOURCE_GROUP]),
4658 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4659 {"drop_role",
4660 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_DROP_ROLE]),
4661 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4662 {"drop_server",
4663 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_DROP_SERVER]),
4664 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4665 {"drop_spatial_reference_system",
4666 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_DROP_SRS]),
4667 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4668 {"drop_table",
4669 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_DROP_TABLE]),
4670 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4671 {"drop_trigger",
4672 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_DROP_TRIGGER]),
4673 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4674 {"drop_user",
4675 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_DROP_USER]),
4676 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4677 {"drop_view",
4678 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_DROP_VIEW]),
4679 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4680 {"empty_query",
4681 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_EMPTY_QUERY]),
4682 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4683 {"execute_sql",
4684 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_EXECUTE]),
4685 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4686 {"explain_other",
4687 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_EXPLAIN_OTHER]),
4688 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4689 {"flush", (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_FLUSH]),
4690 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4691 {"get_diagnostics",
4692 (char *)offsetof(System_status_var,
4693 com_stat[(uint)SQLCOM_GET_DIAGNOSTICS]),
4694 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4695 {"grant", (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_GRANT]),
4696 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4697 {"grant_roles",
4698 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_GRANT_ROLE]),
4699 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4700 {"ha_close",
4701 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_HA_CLOSE]),
4702 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4703 {"ha_open",
4704 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_HA_OPEN]),
4705 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4706 {"ha_read",
4707 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_HA_READ]),
4708 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4709 {"help", (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_HELP]),
4710 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4711 {"import",
4712 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_IMPORT]),
4713 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4714 {"insert",
4715 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_INSERT]),
4716 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4717 {"insert_select",
4718 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_INSERT_SELECT]),
4719 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4720 {"install_component",
4721 (char *)offsetof(System_status_var,
4722 com_stat[(uint)SQLCOM_INSTALL_COMPONENT]),
4723 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4724 {"install_plugin",
4725 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_INSTALL_PLUGIN]),
4726 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4727 {"kill", (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_KILL]),
4728 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4729 {"load", (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_LOAD]),
4730 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4731 {"lock_instance",
4732 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_LOCK_INSTANCE]),
4733 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4734 {"lock_tables",
4735 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_LOCK_TABLES]),
4736 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4737 {"lock_tables_for_backup",
4738 (char *)offsetof(System_status_var,
4739 com_stat[(uint)SQLCOM_LOCK_TABLES_FOR_BACKUP]),
4740 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4741 {"optimize",
4742 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_OPTIMIZE]),
4743 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4744 {"preload_keys",
4745 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_PRELOAD_KEYS]),
4746 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4747 {"prepare_sql",
4748 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_PREPARE]),
4749 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4750 {"purge", (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_PURGE]),
4751 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4752 {"purge_before_date",
4753 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_PURGE_BEFORE]),
4754 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4755 {"release_savepoint",
4756 (char *)offsetof(System_status_var,
4757 com_stat[(uint)SQLCOM_RELEASE_SAVEPOINT]),
4758 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4759 {"rename_table",
4760 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_RENAME_TABLE]),
4761 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4762 {"rename_user",
4763 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_RENAME_USER]),
4764 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4765 {"repair",
4766 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_REPAIR]),
4767 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4768 {"replace",
4769 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_REPLACE]),
4770 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4771 {"replace_select",
4772 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_REPLACE_SELECT]),
4773 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4774 {"reset", (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_RESET]),
4775 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4776 {"resignal",
4777 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_RESIGNAL]),
4778 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4779 {"restart",
4780 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_RESTART_SERVER]),
4781 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4782 {"revoke",
4783 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_REVOKE]),
4784 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4785 {"revoke_all",
4786 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_REVOKE_ALL]),
4787 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4788 {"revoke_roles",
4789 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_REVOKE_ROLE]),
4790 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4791 {"rollback",
4792 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_ROLLBACK]),
4793 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4794 {"rollback_to_savepoint",
4795 (char *)offsetof(System_status_var,
4796 com_stat[(uint)SQLCOM_ROLLBACK_TO_SAVEPOINT]),
4797 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4798 {"savepoint",
4799 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SAVEPOINT]),
4800 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4801 {"select",
4802 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SELECT]),
4803 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4804 {"set_option",
4805 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SET_OPTION]),
4806 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4807 {"set_password",
4808 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SET_PASSWORD]),
4809 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4810 {"set_resource_group",
4811 (char *)offsetof(System_status_var,
4812 com_stat[(uint)SQLCOM_SET_RESOURCE_GROUP]),
4813 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4814 {"set_role",
4815 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SET_ROLE]),
4816 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4817 {"signal",
4818 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SIGNAL]),
4819 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4820 {"show_binlog_events",
4821 (char *)offsetof(System_status_var,
4822 com_stat[(uint)SQLCOM_SHOW_BINLOG_EVENTS]),
4823 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4824 {"show_binlogs",
4825 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_BINLOGS]),
4826 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4827 {"show_charsets",
4828 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_CHARSETS]),
4829 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4830 {"show_client_statistics",
4831 (char *)offsetof(System_status_var,
4832 com_stat[(uint)SQLCOM_SHOW_CLIENT_STATS]),
4833 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4834 {"show_collations",
4835 (char *)offsetof(System_status_var,
4836 com_stat[(uint)SQLCOM_SHOW_COLLATIONS]),
4837 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4838 {"show_create_db",
4839 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_CREATE_DB]),
4840 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4841 {"show_create_event",
4842 (char *)offsetof(System_status_var,
4843 com_stat[(uint)SQLCOM_SHOW_CREATE_EVENT]),
4844 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4845 {"show_create_func",
4846 (char *)offsetof(System_status_var,
4847 com_stat[(uint)SQLCOM_SHOW_CREATE_FUNC]),
4848 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4849 {"show_create_proc",
4850 (char *)offsetof(System_status_var,
4851 com_stat[(uint)SQLCOM_SHOW_CREATE_PROC]),
4852 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4853 {"show_create_table",
4854 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_CREATE]),
4855 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4856 {"show_create_trigger",
4857 (char *)offsetof(System_status_var,
4858 com_stat[(uint)SQLCOM_SHOW_CREATE_TRIGGER]),
4859 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4860 {"show_databases",
4861 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_DATABASES]),
4862 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4863 {"show_engine_logs",
4864 (char *)offsetof(System_status_var,
4865 com_stat[(uint)SQLCOM_SHOW_ENGINE_LOGS]),
4866 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4867 {"show_engine_mutex",
4868 (char *)offsetof(System_status_var,
4869 com_stat[(uint)SQLCOM_SHOW_ENGINE_MUTEX]),
4870 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4871 {"show_engine_status",
4872 (char *)offsetof(System_status_var,
4873 com_stat[(uint)SQLCOM_SHOW_ENGINE_STATUS]),
4874 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4875 {"show_events",
4876 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_EVENTS]),
4877 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4878 {"show_errors",
4879 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_ERRORS]),
4880 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4881 {"show_fields",
4882 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_FIELDS]),
4883 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4884 {"show_function_code",
4885 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_FUNC_CODE]),
4886 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4887 {"show_function_status",
4888 (char *)offsetof(System_status_var,
4889 com_stat[(uint)SQLCOM_SHOW_STATUS_FUNC]),
4890 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4891 {"show_grants",
4892 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_GRANTS]),
4893 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4894 {"show_index_statistics",
4895 (char *)offsetof(System_status_var,
4896 com_stat[(uint)SQLCOM_SHOW_INDEX_STATS]),
4897 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4898 {"show_keys",
4899 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_KEYS]),
4900 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4901 {"show_master_status",
4902 (char *)offsetof(System_status_var,
4903 com_stat[(uint)SQLCOM_SHOW_MASTER_STAT]),
4904 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4905 {"show_open_tables",
4906 (char *)offsetof(System_status_var,
4907 com_stat[(uint)SQLCOM_SHOW_OPEN_TABLES]),
4908 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4909 {"show_plugins",
4910 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_PLUGINS]),
4911 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4912 {"show_privileges",
4913 (char *)offsetof(System_status_var,
4914 com_stat[(uint)SQLCOM_SHOW_PRIVILEGES]),
4915 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4916 {"show_procedure_code",
4917 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_PROC_CODE]),
4918 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4919 {"show_procedure_status",
4920 (char *)offsetof(System_status_var,
4921 com_stat[(uint)SQLCOM_SHOW_STATUS_PROC]),
4922 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4923 {"show_processlist",
4924 (char *)offsetof(System_status_var,
4925 com_stat[(uint)SQLCOM_SHOW_PROCESSLIST]),
4926 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4927 {"show_profile",
4928 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_PROFILE]),
4929 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4930 {"show_profiles",
4931 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_PROFILES]),
4932 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4933 {"show_relaylog_events",
4934 (char *)offsetof(System_status_var,
4935 com_stat[(uint)SQLCOM_SHOW_RELAYLOG_EVENTS]),
4936 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4937 {"show_replicas",
4938 (char *)offsetof(System_status_var,
4939 com_stat[(uint)SQLCOM_SHOW_SLAVE_HOSTS]),
4940 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4941 {"show_slave_hosts",
4942 (char *)offsetof(System_status_var,
4943 com_stat[(uint)SQLCOM_SHOW_SLAVE_HOSTS]),
4944 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4945 {"show_replica_status",
4946 (char *)offsetof(System_status_var,
4947 com_stat[(uint)SQLCOM_SHOW_SLAVE_STAT]),
4948 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4949 {"show_slave_status",
4950 (char *)offsetof(System_status_var,
4951 com_stat[(uint)SQLCOM_SHOW_SLAVE_STAT]),
4952 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4953 {"show_status",
4954 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_STATUS]),
4955 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4956 {"show_storage_engines",
4957 (char *)offsetof(System_status_var,
4958 com_stat[(uint)SQLCOM_SHOW_STORAGE_ENGINES]),
4959 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4960 {"show_table_statistics",
4961 (char *)offsetof(System_status_var,
4962 com_stat[(uint)SQLCOM_SHOW_TABLE_STATS]),
4963 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4964 {"show_table_status",
4965 (char *)offsetof(System_status_var,
4966 com_stat[(uint)SQLCOM_SHOW_TABLE_STATUS]),
4967 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4968 {"show_tables",
4969 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_TABLES]),
4970 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4971 {"show_thread_statistics",
4972 (char *)offsetof(System_status_var,
4973 com_stat[(uint)SQLCOM_SHOW_THREAD_STATS]),
4974 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4975 {"show_triggers",
4976 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_TRIGGERS]),
4977 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4978 {"show_user_statistics",
4979 (char *)offsetof(System_status_var,
4980 com_stat[(uint)SQLCOM_SHOW_USER_STATS]),
4981 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4982 {"show_variables",
4983 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_VARIABLES]),
4984 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4985 {"show_warnings",
4986 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHOW_WARNS]),
4987 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4988 {"show_create_user",
4989 (char *)offsetof(System_status_var,
4990 com_stat[(uint)SQLCOM_SHOW_CREATE_USER]),
4991 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4992 {"shutdown",
4993 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SHUTDOWN]),
4994 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4995 {"replica_start",
4996 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SLAVE_START]),
4997 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
4998 {"slave_start",
4999 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SLAVE_START]),
5000 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
5001 {"replica_stop",
5002 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SLAVE_STOP]),
5003 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
5004 {"slave_stop",
5005 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_SLAVE_STOP]),
5006 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
5007 {"group_replication_start",
5008 (char *)offsetof(System_status_var,
5009 com_stat[(uint)SQLCOM_START_GROUP_REPLICATION]),
5010 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
5011 {"group_replication_stop",
5012 (char *)offsetof(System_status_var,
5013 com_stat[(uint)SQLCOM_STOP_GROUP_REPLICATION]),
5014 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
5015 {"stmt_execute", (char *)offsetof(System_status_var, com_stmt_execute),
5016 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
5017 {"stmt_close", (char *)offsetof(System_status_var, com_stmt_close),
5018 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
5019 {"stmt_fetch", (char *)offsetof(System_status_var, com_stmt_fetch),
5020 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
5021 {"stmt_prepare", (char *)offsetof(System_status_var, com_stmt_prepare),
5022 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
5023 {"stmt_reset", (char *)offsetof(System_status_var, com_stmt_reset),
5024 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
5025 {"stmt_send_long_data",
5026 (char *)offsetof(System_status_var, com_stmt_send_long_data),
5027 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
5028 {"truncate",
5029 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_TRUNCATE]),
5030 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
5031 {"uninstall_component",
5032 (char *)offsetof(System_status_var,
5033 com_stat[(uint)SQLCOM_UNINSTALL_COMPONENT]),
5034 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
5035 {"uninstall_plugin",
5036 (char *)offsetof(System_status_var,
5037 com_stat[(uint)SQLCOM_UNINSTALL_PLUGIN]),
5038 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
5039 {"unlock_instance",
5040 (char *)offsetof(System_status_var,
5041 com_stat[(uint)SQLCOM_UNLOCK_INSTANCE]),
5042 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
5043 {"unlock_tables",
5044 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_UNLOCK_TABLES]),
5045 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
5046 {"update",
5047 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_UPDATE]),
5048 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
5049 {"update_multi",
5050 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_UPDATE_MULTI]),
5051 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
5052 {"xa_commit",
5053 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_XA_COMMIT]),
5054 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
5055 {"xa_end",
5056 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_XA_END]),
5057 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
5058 {"xa_prepare",
5059 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_XA_PREPARE]),
5060 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
5061 {"xa_recover",
5062 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_XA_RECOVER]),
5063 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
5064 {"xa_rollback",
5065 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_XA_ROLLBACK]),
5066 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
5067 {"xa_start",
5068 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_XA_START]),
5069 SHOW_LONG_STATUS, SHOW_SCOPE_ALL},
5070 {NullS, NullS, SHOW_LONG, SHOW_SCOPE_ALL}};
5071
5072 LEX_CSTRING sql_statement_names[(uint)SQLCOM_END + 1];
5073
5074 9813 static void init_sql_statement_names() {
5075 9813 char *first_com = (char *)offsetof(System_status_var, com_stat[0]);
5076 9813 char *last_com =
5077 (char *)offsetof(System_status_var, com_stat[(uint)SQLCOM_END]);
5078 9813 int record_size = (char *)offsetof(System_status_var, com_stat[1]) -
5079 (char *)offsetof(System_status_var, com_stat[0]);
5080 char *ptr;
5081 uint i;
5082 uint com_index;
5083
5084
2/2
✓ Branch 0 taken 1648584 times.
✓ Branch 1 taken 9813 times.
1658397 for (i = 0; i < ((uint)SQLCOM_END + 1); i++)
5085 1648584 sql_statement_names[i] = {STRING_WITH_LEN("")};
5086
5087 9813 SHOW_VAR *var = &com_status_vars[0];
5088
2/2
✓ Branch 0 taken 1756527 times.
✓ Branch 1 taken 9813 times.
1766340 while (var->name != nullptr) {
5089 1756527 ptr = var->value;
5090
3/4
✓ Branch 0 taken 1687836 times.
✓ Branch 1 taken 68691 times.
✓ Branch 2 taken 1687836 times.
✗ Branch 3 not taken.
1756527 if ((first_com <= ptr) && (ptr <= last_com)) {
5091 1687836 com_index = ((int)(ptr - first_com)) / record_size;
5092
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1687836 times.
1687836 assert(com_index < (uint)SQLCOM_END);
5093 1687836 sql_statement_names[com_index].str = var->name;
5094 /* TODO: Change SHOW_VAR::name to a LEX_STRING, to avoid strlen() */
5095 1687836 sql_statement_names[com_index].length = strlen(var->name);
5096 }
5097 1756527 var++;
5098 }
5099
5100
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9813 times.
9813 assert(strcmp(sql_statement_names[(uint)SQLCOM_SELECT].str, "select") == 0);
5101
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9813 times.
9813 assert(strcmp(sql_statement_names[(uint)SQLCOM_SIGNAL].str, "signal") == 0);
5102
5103 9813 sql_statement_names[(uint)SQLCOM_END].str = "error";
5104 9813 }
5105
5106 #ifdef HAVE_PSI_STATEMENT_INTERFACE
5107 PSI_statement_info sql_statement_info[(uint)SQLCOM_END + 1];
5108 PSI_statement_info com_statement_info[(uint)COM_END + 1];
5109
5110 /**
5111 Initialize the command names array.
5112 Since we do not want to maintain a separate array,
5113 this is populated from data mined in com_status_vars,
5114 which already has one name for each command.
5115 */
5116 9813 static void init_sql_statement_info() {
5117 uint i;
5118
5119
2/2
✓ Branch 0 taken 1648584 times.
✓ Branch 1 taken 9813 times.
1658397 for (i = 0; i < ((uint)SQLCOM_END + 1); i++) {
5120 1648584 sql_statement_info[i].m_name = sql_statement_names[i].str;
5121 1648584 sql_statement_info[i].m_flags = 0;
5122 1648584 sql_statement_info[i].m_documentation = PSI_DOCUMENT_ME;
5123 }
5124
5125 /* "statement/sql/error" represents broken queries (syntax error). */
5126 9813 sql_statement_info[(uint)SQLCOM_END].m_name = "error";
5127 9813 sql_statement_info[(uint)SQLCOM_END].m_flags = 0;
5128 9813 sql_statement_info[(uint)SQLCOM_END].m_documentation =
5129 "Invalid SQL queries (syntax error).";
5130
5131 /* "statement/sql/clone" will mutate to clone plugin statement */
5132 9813 sql_statement_info[(uint)SQLCOM_CLONE].m_flags = PSI_FLAG_MUTABLE;
5133 9813 }
5134
5135 9813 static void init_com_statement_info() {
5136 uint index;
5137
5138
2/2
✓ Branch 0 taken 343455 times.
✓ Branch 1 taken 9813 times.
353268 for (index = 0; index < (uint)COM_END + 1; index++) {
5139 343455 com_statement_info[index].m_name =
5140 343455 Command_names::str_notranslate(index).c_str();
5141 343455 com_statement_info[index].m_flags = 0;
5142 343455 com_statement_info[index].m_documentation = PSI_DOCUMENT_ME;
5143 }
5144
5145 /* "statement/abstract/query" can mutate into "statement/sql/..." */
5146 9813 com_statement_info[(uint)COM_QUERY].m_flags = PSI_FLAG_MUTABLE;
5147 9813 com_statement_info[(uint)COM_QUERY].m_documentation =
5148 "SQL query just received from the network. "
5149 "At this point, the real statement type is unknown, "
5150 "the type will be refined after SQL parsing.";
5151
5152 /* "statement/com/clone" will mutate to clone plugin statement */
5153 9813 com_statement_info[(uint)COM_CLONE].m_flags = PSI_FLAG_MUTABLE;
5154 9813 }
5155 #endif
5156
5157 /**
5158 Parse @@authentication_policy variable value.
5159
5160 @param [in] val Buffer holding variable value.
5161 @param [out] policy_list Vector holding the parsed values.
5162
5163 @retval false OK
5164 @retval true Error
5165 */
5166 18764 bool parse_authentication_policy(char *val,
5167 std::vector<std::string> &policy_list) {
5168 18764 std::string token;
5169
1/2
✓ Branch 0 taken 18764 times.
✗ Branch 1 not taken.
18764 std::string policy_val(val);
5170
2/4
✓ Branch 0 taken 18764 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18764 times.
✗ Branch 3 not taken.
37528 std::stringstream policy_str(val);
5171 18764 bool is_empty = false;
5172 /* count comma */
5173
1/2
✓ Branch 0 taken 18764 times.
✗ Branch 1 not taken.
18764 size_t comma_cnt = std::count(policy_val.begin(), policy_val.end(), ',');
5174
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18764 times.
18764 if (comma_cnt >= MAX_AUTH_FACTORS) return true;
5175 /*
5176 While parsing ensure that an empty value which means an optional nth factor,
5177 should be followed with an empty value only.
5178 Below are some invalid values:
5179 'caching_sha2_password,,authentication_fido'
5180 ',authentication_fido,authentication_ldap_simple'
5181 ',authentication_fido,'
5182 ',,'
5183 */
5184
4/6
✓ Branch 0 taken 56292 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 56292 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 37528 times.
✓ Branch 5 taken 18764 times.
56292 while (getline(policy_str, token, ',')) {
5185
1/2
✓ Branch 0 taken 37528 times.
✗ Branch 1 not taken.
37528 std::string s(token);
5186 /* trim spaces */
5187
2/4
✓ Branch 0 taken 37528 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37528 times.
✗ Branch 3 not taken.
37528 s.erase(std::remove(s.begin(), s.end(), ' '), s.end());
5188
4/6
✓ Branch 0 taken 18764 times.
✓ Branch 1 taken 18764 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18764 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 37528 times.
37528 if (s.length() && is_empty) {
5189 policy_list.clear();
5190 return true;
5191 };
5192
2/2
✓ Branch 0 taken 18764 times.
✓ Branch 1 taken 18764 times.
37528 if (!s.length()) is_empty = true;
5193
1/2
✓ Branch 0 taken 37528 times.
✗ Branch 1 not taken.
37528 policy_list.push_back(s);
5194
1/2
✓ Branch 0 taken 37528 times.
✗ Branch 1 not taken.
37528 }
5195 /*
5196 Values like 'caching_sha2_password,authentication_fido,' or
5197 'caching_sha2_password,,' will not capture the last empty value, thus append
5198 an empty value to the list.
5199 */
5200
3/6
✓ Branch 0 taken 18764 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18764 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18764 times.
✗ Branch 5 not taken.
37528 if ((comma_cnt == policy_list.size()) &&
5201 18764 policy_list.size() < MAX_AUTH_FACTORS)
5202
2/4
✓ Branch 0 taken 18764 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18764 times.
✗ Branch 3 not taken.
18764 policy_list.push_back("");
5203
5204
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18764 times.
18764 if (policy_list.size() > MAX_AUTH_FACTORS) {
5205 policy_list.clear();
5206 return true;
5207 }
5208 18764 return false;
5209 18764 }
5210
5211 /**
5212 Validate @@authentication_policy variable value.
5213
5214 @param [in] val Buffer holding variable value.
5215
5216 @retval false success
5217 @retval true failure
5218 */
5219 9382 bool validate_authentication_policy(char *val) {
5220 9382 std::vector<std::string> list;
5221
2/4
✓ Branch 0 taken 9382 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9382 times.
9382 if (parse_authentication_policy(val, list)) return true;
5222
2/2
✓ Branch 0 taken 28146 times.
✓ Branch 1 taken 9382 times.
37528 for (auto it = list.begin(); it != list.end(); it++) {
5223 /* plugin name in first place holder cannot be empty */
5224
2/2
✓ Branch 0 taken 18764 times.
✓ Branch 1 taken 9382 times.
28146 if (!it->length()) {
5225
3/6
✓ Branch 0 taken 18764 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18764 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 18764 times.
18764 if (list.size() == 1 || it == list.begin()) return true;
5226 }
5227 /* skip special characters like * and <empty> string */
5228
2/2
✓ Branch 0 taken 18764 times.
✓ Branch 1 taken 9382 times.
37528 if (!it->length()) continue;
5229
1/2
✓ Branch 0 taken 9382 times.
✗ Branch 1 not taken.
9382 if (!it->compare("*")) continue;
5230 /* validate plugin name */
5231 plugin_ref p = my_plugin_lock_by_name(nullptr, to_lex_cstring(it->c_str()),
5232 MYSQL_AUTHENTICATION_PLUGIN);
5233 if (!p) goto error;
5234 st_mysql_auth *auth = (st_mysql_auth *)plugin_decl(p)->info;
5235 /*
5236 ensure 2nd and 3rd factor auth plugins which store password in mysql
5237 server are not allowed.
5238 */
5239 if (it != list.begin() &&
5240 auth->authentication_flags & AUTH_FLAG_USES_INTERNAL_STORAGE) {
5241 authentication_policy_plugin_ref.push_back(p);
5242 goto error;
5243 }
5244 /*
5245 ensure plugin name in first place holder cannot be auth plugin
5246 which requires registration step.
5247 */
5248 if (it == list.begin() &&
5249 auth->authentication_flags & AUTH_FLAG_REQUIRES_REGISTRATION) {
5250 authentication_policy_plugin_ref.push_back(p);
5251 goto error;
5252 }
5253 authentication_policy_plugin_ref.push_back(p);
5254 }
5255 9382 return false;
5256 error:
5257 for (auto p : authentication_policy_plugin_ref) plugin_unlock(nullptr, p);
5258 authentication_policy_plugin_ref.clear();
5259 return true;
5260 9382 }
5261
5262 /**
5263 Update @@authentication_policy variable value.
5264
5265 @retval false success
5266 @retval true failure
5267 */
5268 9382 bool update_authentication_policy() {
5269 9382 std::vector<std::string> list;
5270
2/4
✓ Branch 0 taken 9382 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9382 times.
9382 if (parse_authentication_policy(opt_authentication_policy, list)) return true;
5271 /* update the actual policy list only after validation is successful */
5272
1/2
✓ Branch 0 taken 9382 times.
✗ Branch 1 not taken.
9382 authentication_policy_list = list;
5273 /* release plugin reference */
5274
1/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9382 times.
9382 for (auto p : authentication_policy_plugin_ref) plugin_unlock(nullptr, p);
5275 9382 authentication_policy_plugin_ref.clear();
5276 9382 return false;
5277 9382 }
5278 /**
5279 Create a replication file name or base for file names.
5280
5281 @param key Instrumentation key used to track allocations
5282 @param[in] opt Value of option, or NULL
5283 @param[in] def Default value if option value is not set.
5284 @param[in] ext Extension to use for the path
5285
5286 @returns Pointer to string containing the full file path, or NULL if
5287 it was not possible to create the path.
5288 */
5289 37952 static inline const char *rpl_make_log_name(PSI_memory_key key, const char *opt,
5290 const char *def, const char *ext) {
5291
1/2
✓ Branch 0 taken 37952 times.
✗ Branch 1 not taken.
37952 DBUG_TRACE;
5292
3/12
✓ Branch 0 taken 37952 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37952 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 37952 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
37952 DBUG_PRINT("enter", ("opt: %s, def: %s, ext: %s", (opt && opt[0]) ? opt : "",
5293 def, ext));
5294 char buff[FN_REFLEN];
5295 /*
5296 opt[0] needs to be checked to make sure opt name is not an empty
5297 string, in case it is an empty string default name will be considered
5298 */
5299
3/4
✓ Branch 0 taken 12253 times.
✓ Branch 1 taken 25699 times.
✓ Branch 2 taken 12253 times.
✗ Branch 3 not taken.
37952 const char *base = (opt && opt[0]) ? opt : def;
5300 37952 unsigned int options = MY_REPLACE_EXT | MY_UNPACK_FILENAME | MY_SAFE_PATH;
5301
5302 /* mysql_real_data_home_ptr may be null if no value of datadir has been
5303 specified through command-line or througha cnf file. If that is the
5304 case we make mysql_real_data_home_ptr point to mysql_real_data_home
5305 which, in that case holds the default path for data-dir.
5306 */
5307
5308
3/4
✓ Branch 0 taken 37952 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 37948 times.
37952 DBUG_EXECUTE_IF("emulate_empty_datadir_param",
5309 { mysql_real_data_home_ptr = nullptr; };);
5310
5311
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 37948 times.
37952 if (mysql_real_data_home_ptr == nullptr)
5312 4 mysql_real_data_home_ptr = mysql_real_data_home;
5313
5314
2/4
✓ Branch 0 taken 37952 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37952 times.
✗ Branch 3 not taken.
37952 if (fn_format(buff, base, mysql_real_data_home_ptr, ext, options))
5315
1/2
✓ Branch 0 taken 37952 times.
✗ Branch 1 not taken.
37952 return my_strdup(key, buff, MYF(0));
5316 else
5317 return nullptr;
5318 37952 }
5319
5320 9824 int init_common_variables() {
5321 9824 my_decimal_set_zero(&decimal_zero); // set decimal_zero constant;
5322 9824 tzset(); // Set tzname
5323
5324 9824 max_system_variables.pseudo_thread_id = (my_thread_id)~0;
5325 9824 server_start_time = flush_status_time = time(nullptr);
5326
5327
1/2
✓ Branch 0 taken 9824 times.
✗ Branch 1 not taken.
9824 binlog_filter = new Rpl_filter;
5328
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9824 times.
9824 if (!binlog_filter) {
5329 LogErr(ERROR_LEVEL, ER_RPL_BINLOG_FILTERS_OOM, strerror(errno));
5330 return 1;
5331 }
5332
5333
3/6
✓ Branch 0 taken 9824 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9824 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 9824 times.
9824 if (init_thread_environment() || mysql_init_variables()) return 1;
5334
5335 {
5336 #ifdef _WIN32
5337 strmake(system_time_zone_dst_off, _tzname[0],
5338 sizeof(system_time_zone_dst_off) - 1);
5339 strmake(system_time_zone_dst_on, _tzname[1],
5340 sizeof(system_time_zone_dst_on) - 1);
5341 #else
5342 9824 strmake(system_time_zone_dst_off, tzname[0],
5343 sizeof(system_time_zone_dst_off) - 1);
5344 9824 strmake(system_time_zone_dst_on, tzname[1],
5345 sizeof(system_time_zone_dst_on) - 1);
5346 #endif
5347 }
5348 /*
5349 We set SYSTEM time zone as reasonable default and
5350 also for failure of my_tz_init() and bootstrap mode.
5351 If user explicitly set time zone with --default-time-zone
5352 option we will change this value in my_tz_init().
5353 */
5354 9824 global_system_variables.time_zone = my_tz_SYSTEM;
5355
5356 #ifdef HAVE_PSI_INTERFACE
5357 /*
5358 Complete the mysql_bin_log initialization.
5359 Instrumentation keys are known only after the performance schema
5360 initialization, and can not be set in the MYSQL_BIN_LOG constructor (called
5361 before main()).
5362 */
5363 9824 mysql_bin_log.set_psi_keys(
5364 key_BINLOG_LOCK_index, key_BINLOG_LOCK_commit,
5365 key_BINLOG_LOCK_commit_queue, key_BINLOG_LOCK_done,
5366 key_BINLOG_LOCK_flush_queue, key_BINLOG_LOCK_log,
5367 key_BINLOG_LOCK_binlog_end_pos, key_BINLOG_LOCK_sync,
5368 key_BINLOG_LOCK_sync_queue, key_BINLOG_LOCK_xids, key_BINLOG_COND_done,
5369 key_BINLOG_COND_flush_queue, key_BINLOG_update_cond,
5370 key_BINLOG_prep_xids_cond, key_file_binlog, key_file_binlog_index,
5371 key_file_binlog_cache, key_file_binlog_index_cache);
5372 #endif
5373
5374 /*
5375 Init mutexes for the global MYSQL_BIN_LOG objects.
5376 As safe_mutex depends on what MY_INIT() does, we can't init the mutexes of
5377 global MYSQL_BIN_LOGs in their constructors, because then they would be
5378 inited before MY_INIT(). So we do it here.
5379 */
5380 9824 mysql_bin_log.init_pthread_objects();
5381
5382 /* TODO: remove this when my_time_t is 64 bit compatible */
5383
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9824 times.
9824 if (!is_time_t_valid_for_timestamp(server_start_time)) {
5384 LogErr(ERROR_LEVEL, ER_UNSUPPORTED_DATE);
5385 return 1;
5386 }
5387
5388
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9824 times.
9824 if (gethostname(glob_hostname, sizeof(glob_hostname)) < 0) {
5389 strmake(glob_hostname, STRING_WITH_LEN("localhost"));
5390 LogErr(WARNING_LEVEL, ER_CALL_ME_LOCALHOST, glob_hostname);
5391 strmake(default_logfile_name, STRING_WITH_LEN("mysql"));
5392 } else
5393 9824 strmake(default_logfile_name, glob_hostname,
5394 sizeof(default_logfile_name) - 5);
5395
5396 9824 strmake(default_binlogfile_name, STRING_WITH_LEN("binlog"));
5397
3/4
✓ Branch 0 taken 9611 times.
✓ Branch 1 taken 213 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9611 times.
9824 if (opt_initialize || opt_initialize_insecure) {
5398 /*
5399 System tables initialization are not binary logged (regardless
5400 --log-bin option).
5401
5402 Disable binary log while executing any user script sourced while
5403 initializing system except if explicitly requested.
5404 */
5405 213 opt_bin_log = false;
5406 }
5407
5408 #ifdef WITH_WSREP
5409
2/4
✓ Branch 0 taken 9824 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9824 times.
✗ Branch 3 not taken.
9824 if (0 == wsrep_node_name || 0 == wsrep_node_name[0]) {
5410 9824 my_free(const_cast<char *>(wsrep_node_name));
5411 /* hostname on linux is bounded by HOST_NAME_MAX (64 bytes). */
5412 9824 wsrep_node_name = my_strndup(key_memory_wsrep, glob_hostname,
5413 WSREP_HOSTNAME_LENGTH, MYF(MY_WME));
5414 }
5415 #endif /* WITH_WSREP */
5416
5417 9824 strmake(pidfile_name, default_logfile_name, sizeof(pidfile_name) - 5);
5418 9824 my_stpcpy(fn_ext(pidfile_name), ".pid"); // Add proper extension
5419
5420 /*
5421 The default-storage-engine entry in my_long_options should have a
5422 non-null default value. It was earlier initialized as
5423 (longlong)"MyISAM" in my_long_options but this triggered a
5424 compiler error in the Sun Studio 12 compiler. As a work-around we
5425 set the def_value member to 0 in my_long_options and initialize it
5426 to the correct value here.
5427
5428 From MySQL 5.5 onwards, the default storage engine is InnoDB.
5429 */
5430 9824 default_storage_engine = "InnoDB";
5431 9824 default_tmp_storage_engine = default_storage_engine;
5432
5433 /*
5434 Add server status variables to the dynamic list of
5435 status variables that is shown by SHOW STATUS.
5436 Later, in plugin_register_builtin_and_init_core_se(),
5437 plugin_register_dynamic_and_init_all() and
5438 mysql_install_plugin(), new entries could be added
5439 to that list.
5440 */
5441
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9824 times.
9824 if (add_status_vars(status_vars)) return 1; // an error was already reported
5442
5443 #ifndef NDEBUG
5444 /*
5445 We have few debug-only commands in com_status_vars, only visible in debug
5446 builds. for simplicity we enable the assert only in debug builds
5447
5448 There are 8 Com_ variables which don't have corresponding SQLCOM_ values:
5449 (TODO strictly speaking they shouldn't be here, should not have Com_ prefix
5450 that is. Perhaps Stmt_ ? Comstmt_ ? Prepstmt_ ?)
5451
5452 Com_admin_commands => com_other
5453 Com_stmt_close => com_stmt_close
5454 Com_stmt_execute => com_stmt_execute
5455 Com_stmt_fetch => com_stmt_fetch
5456 Com_stmt_prepare => com_stmt_prepare
5457 Com_stmt_reprepare => com_stmt_reprepare
5458 Com_stmt_reset => com_stmt_reset
5459 Com_stmt_send_long_data => com_stmt_send_long_data
5460
5461 We also have aliases for 5 com_status_vars:
5462
5463 Com_slave_start => Com_replica_start
5464 Com_slave_stop => Com_replica_stop
5465 Com_show_slave_status => Com_show_replica_status
5466 Com_show_slave_hosts => Com_show_replicas
5467 Com_change_master => Com_change_replication_source
5468
5469 With this correction the number of Com_ variables (number of elements in
5470 the array, excluding the last element - terminator) must match the number
5471 of SQLCOM_ constants.
5472 */
5473 static_assert(sizeof(com_status_vars) / sizeof(com_status_vars[0]) - 1 ==
5474 SQLCOM_END + 12,
5475 "");
5476 #endif
5477
5478 #ifdef WITH_WSREP
5479 /* This is a protection against mutually incompatible option values. */
5480
3/8
✓ Branch 0 taken 9824 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9824 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 9824 times.
9824 if (WSREP_ON && wsrep_check_opts(remaining_argc, remaining_argv)) return 1;
5481 #endif /* WITH_WSREP */
5482
5483
2/2
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 9790 times.
9824 if (get_options(&remaining_argc, &remaining_argv)) return 1;
5484
5485 /*
5486 The opt_bin_log can be false (binary log is disabled) only if
5487 --skip-log-bin/--disable-log-bin is configured or while the
5488 system is initializing.
5489 */
5490
2/2
✓ Branch 0 taken 535 times.
✓ Branch 1 taken 9255 times.
9790 if (!opt_bin_log) {
5491 /*
5492 The log-replica-updates should be disabled if binary log is disabled
5493 and --log-replica-updates option is not set explicitly on command
5494 line or configuration file.
5495 */
5496
2/2
✓ Branch 0 taken 350 times.
✓ Branch 1 taken 185 times.
535 if (!log_replica_updates_supplied) opt_log_replica_updates = false;
5497 }
5498
5499 #ifdef WITH_WSREP
5500
5501 /* We could have checked these in wsrep_check_opts but then part of them
5502 are dependent on pxc-strict-mode. While we could have parsed value of
5503 pxc-strict-mode, validation for valid value would be difficult. */
5504 9790 bool wsrep_provider_loaded =
5505
3/4
✓ Branch 0 taken 9790 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 460 times.
✓ Branch 3 taken 9330 times.
9790 !(strlen(wsrep_provider) == 0 || !strcmp(wsrep_provider, WSREP_NONE));
5506
5507 /* Turn-off WSREP_ON since the loader is not yet loaded and if the checks
5508 below hit some error then error flow should operate with wsrep_on=off. */
5509 9790 global_system_variables.wsrep_on = false;
5510
5511
2/2
✓ Branch 0 taken 213 times.
✓ Branch 1 taken 9577 times.
9790 if (opt_initialize) {
5512 /* Node is running bootstrap mode pxc-strict-mode = DISABLED. */
5513
9/18
✓ Branch 0 taken 213 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 213 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 213 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 213 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 213 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 213 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 213 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 213 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 17 taken 213 times.
213 WSREP_WARN(
5514 "Node is running in bootstrap/initialize mode."
5515 " Disabling pxc_strict_mode checks");
5516 213 pxc_strict_mode = PXC_STRICT_MODE_DISABLED;
5517
6/6
✓ Branch 0 taken 9560 times.
✓ Branch 1 taken 17 times.
✓ Branch 2 taken 9100 times.
✓ Branch 3 taken 460 times.
✓ Branch 4 taken 9100 times.
✓ Branch 5 taken 477 times.
9577 } else if (!is_help_or_validate_option() && wsrep_provider_loaded == false) {
5518 /* Node is not a cluster node pxc-strict-mode will be defaulted
5519 to DISABLED */
5520
9/18
✓ Branch 0 taken 9100 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9100 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9100 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 9100 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 9100 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 9100 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 9100 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 9100 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 17 taken 9100 times.
9100 WSREP_WARN("Node is not a cluster node. Disabling pxc_strict_mode");
5521 9100 pxc_strict_mode = PXC_STRICT_MODE_DISABLED;
5522 }
5523
5524 /* Validate if server initial settings are pxc-strict-mode compatible.*/
5525
5526 /* wsrep_replicate_myisam (recommended value = OFF) */
5527
4/4
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 9330 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 459 times.
9790 if (wsrep_provider_loaded && global_system_variables.wsrep_replicate_myisam) {
5528
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 switch (pxc_strict_mode) {
5529 case PXC_STRICT_MODE_DISABLED:
5530 break;
5531 case PXC_STRICT_MODE_PERMISSIVE:
5532 WSREP_WARN(
5533 "Percona-XtraDB-Cluster doesn't recommend use of MyISAM"
5534 " table replication feature"
5535 " with pxc_strict_mode = PERMISSIVE");
5536 break;
5537 1 case PXC_STRICT_MODE_ENFORCING:
5538 case PXC_STRICT_MODE_MASTER:
5539 default:
5540
9/18
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
1 WSREP_FATAL(
5541 "Percona-XtraDB-Cluster prohibits use of MyISAM"
5542 " table replication feature"
5543 " with pxc_strict_mode = ENFORCING or MASTER");
5544 1 return 1;
5545 break;
5546 }
5547 }
5548
5549 /* binlog_format (recommended value = ROW) */
5550
2/2
✓ Branch 0 taken 459 times.
✓ Branch 1 taken 9330 times.
9789 if (wsrep_provider_loaded &&
5551
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 458 times.
459 global_system_variables.binlog_format != BINLOG_FORMAT_ROW) {
5552 1 switch (pxc_strict_mode) {
5553 case PXC_STRICT_MODE_DISABLED:
5554 case PXC_STRICT_MODE_PERMISSIVE:
5555 case PXC_STRICT_MODE_ENFORCING:
5556 case PXC_STRICT_MODE_MASTER:
5557 default:
5558
9/18
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
1 WSREP_FATAL(
5559 "Percona-XtraDB-Cluster prohibits setting"
5560 " binlog_format to STATEMENT or MIXED at global level");
5561 1 return 1;
5562 break;
5563 }
5564 }
5565
5566 /* log_output (recommended value = FILE/NONE) */
5567
4/4
✓ Branch 0 taken 458 times.
✓ Branch 1 taken 9330 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 457 times.
9788 if (wsrep_provider_loaded && (log_output_options & LOG_TABLE)) {
5568
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 switch (pxc_strict_mode) {
5569 case PXC_STRICT_MODE_DISABLED:
5570 break;
5571 case PXC_STRICT_MODE_PERMISSIVE:
5572 WSREP_WARN(
5573 "Percona-XtraDB-Cluster doesn't recommend setting log_output"
5574 " to TABLE with pxc_strict_mode = PERMISSIVE");
5575 break;
5576 1 case PXC_STRICT_MODE_ENFORCING:
5577 case PXC_STRICT_MODE_MASTER:
5578 default:
5579
9/18
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
1 WSREP_FATAL(
5580 "Percona-XtraDB-Cluster prohibits setting log_output"
5581 " to TABLE with pxc_strict_mode = ENFORCING or MASTER");
5582 1 return 1;
5583 break;
5584 }
5585 }
5586
5587
4/4
✓ Branch 0 taken 457 times.
✓ Branch 1 taken 9330 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 456 times.
9787 if (wsrep_provider_loaded && wsrep_desync) {
5588
9/18
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
1 WSREP_FATAL(
5589 "Can't desync a non-synced node."
5590 " (Node is yet not SYNCED with cluster)");
5591 1 return 1;
5592 }
5593
5594 9786 const char *WSREP_SST_MYSQLDUMP = "mysqldump";
5595
3/4
✓ Branch 0 taken 456 times.
✓ Branch 1 taken 9330 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 456 times.
9786 if (wsrep_provider_loaded && !strcmp(WSREP_SST_MYSQLDUMP, wsrep_sst_method)) {
5596 WSREP_FATAL(
5597 "Percona-XtraDB-Cluster doesn't support SST through mysqldump."
5598 " Please switch to use xtrabackup-v2.");
5599 return 1;
5600 }
5601
5602 9786 const char *WSREP_SST_RSYNC = "rsync";
5603
3/4
✓ Branch 0 taken 456 times.
✓ Branch 1 taken 9330 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 456 times.
9786 if (wsrep_provider_loaded && !strcmp(WSREP_SST_RSYNC, wsrep_sst_method)) {
5604 WSREP_FATAL(
5605 "Percona-XtraDB-Cluster doesn't support SST through rsync."
5606 " Please switch to use xtrabackup-v2.");
5607 return 1;
5608 }
5609
5610 /* Restore wsrep_on after passing all the check.
5611 Since the loader is not yet loaded flow relies on the wsrep_on to filter
5612 WSREP statements. */
5613 9786 global_system_variables.wsrep_on = true;
5614
5615
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9786 times.
9786 if (wsrep_setup_allowed_sst_methods()) return 1;
5616
5617 /*
5618 We need to initialize auxiliary variables, that will be
5619 further keep the original values of auto-increment options
5620 as they set by the user. These variables used to restore
5621 user-defined values of the auto-increment options after
5622 setting of the wsrep_auto_increment_control to 'OFF'.
5623 */
5624 9786 global_system_variables.saved_auto_increment_increment =
5625 9786 global_system_variables.auto_increment_increment;
5626 9786 global_system_variables.saved_auto_increment_offset =
5627 9786 global_system_variables.auto_increment_offset;
5628 #endif /* WITH_WSREP */
5629
5630
1/2
✓ Branch 0 taken 9786 times.
✗ Branch 1 not taken.
9786 if (opt_protocol_compression_algorithms) {
5631
1/2
✓ Branch 0 taken 9786 times.
✗ Branch 1 not taken.
19572 if ((opt_protocol_compression_algorithms[0] == 0) ||
5632
3/4
✓ Branch 0 taken 9786 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 9785 times.
9786 (validate_compression_attributes(
5633
6/16
✓ Branch 0 taken 9786 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9786 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9786 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 9786 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 9785 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
19572 std::string(opt_protocol_compression_algorithms), std::string(),
5634 true))) {
5635 /*
5636 --protocol-compression-algorithms is set to invalid value, resetting
5637 its value to default "zlib,zstd,uncompressed"
5638 */
5639 1 opt_protocol_compression_algorithms =
5640 const_cast<char *>(PROTOCOL_COMPRESSION_DEFAULT_VALUE);
5641
7/14
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
1 LogErr(WARNING_LEVEL, ER_PROTOCOL_COMPRESSION_RESET_LOG);
5642 }
5643 }
5644 9786 update_parser_max_mem_size();
5645
5646
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9786 times.
9786 if (set_default_auth_plugin(default_auth_plugin,
5647 strlen(default_auth_plugin))) {
5648 LogErr(ERROR_LEVEL, ER_AUTH_CANT_SET_DEFAULT_PLUGIN);
5649 return 1;
5650 }
5651 9786 set_server_version();
5652
5653
2/2
✓ Branch 0 taken 9768 times.
✓ Branch 1 taken 18 times.
9786 if (!is_help_or_validate_option()) {
5654
7/14
✓ Branch 0 taken 9768 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9768 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9768 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 9768 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 9768 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 9768 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 9768 times.
✗ Branch 13 not taken.
9768 LogErr(INFORMATION_LEVEL, ER_BASEDIR_SET_TO, mysql_home);
5655 }
5656
5/6
✓ Branch 0 taken 9781 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 9568 times.
✓ Branch 3 taken 213 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 9568 times.
9786 if (!opt_validate_config && (opt_initialize || opt_initialize_insecure)) {
5657
7/14
✓ Branch 0 taken 213 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 213 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 213 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 213 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 213 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 213 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 213 times.
✗ Branch 13 not taken.
213 LogErr(SYSTEM_LEVEL, ER_STARTING_INIT, my_progname, server_version,
5658 (ulong)getpid());
5659
2/2
✓ Branch 0 taken 9556 times.
✓ Branch 1 taken 17 times.
9573 } else if (!is_help_or_validate_option()) {
5660
7/14
✓ Branch 0 taken 9556 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9556 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9556 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 9556 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 9556 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 9556 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 9556 times.
✗ Branch 13 not taken.
9556 LogErr(SYSTEM_LEVEL, ER_STARTING_AS, my_progname, server_version,
5661 (ulong)getpid());
5662 }
5663
3/4
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 9773 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 13 times.
9786 if (opt_help && !opt_verbose) unireg_abort(MYSQLD_SUCCESS_EXIT);
5664
5665
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9786 times.
9786 DBUG_PRINT("info", ("%s Ver %s for %s on %s\n", my_progname, server_version,
5666 SYSTEM_TYPE, MACHINE_TYPE));
5667
5668 #ifdef HAVE_LINUX_LARGE_PAGES
5669 /* Initialize large page size */
5670
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 9786 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9786 times.
9786 if (opt_large_pages && (opt_large_page_size = my_get_large_page_size())) {
5671 DBUG_PRINT("info",
5672 ("Large page set, large_page_size = %d", opt_large_page_size));
5673 } else {
5674 9786 opt_large_pages = false;
5675 /*
5676 Either not configured to use large pages or Linux haven't
5677 been compiled with large page support
5678 */
5679 }
5680 #endif /* HAVE_LINUX_LARGE_PAGES */
5681 #ifdef HAVE_SOLARIS_LARGE_PAGES
5682 #define LARGE_PAGESIZE (4 * 1024 * 1024) /* 4MB */
5683 #define SUPER_LARGE_PAGESIZE (256 * 1024 * 1024) /* 256MB */
5684 if (opt_large_pages) {
5685 /*
5686 tell the kernel that we want to use 4/256MB page for heap storage
5687 and also for the stack. We use 4 MByte as default and if the
5688 super-large-page is set we increase it to 256 MByte. 256 MByte
5689 is for server installations with GBytes of RAM memory where
5690 the MySQL Server will have page caches and other memory regions
5691 measured in a number of GBytes.
5692 We use as big pages as possible which isn't bigger than the above
5693 desired page sizes.
5694 */
5695 int nelem;
5696 size_t max_desired_page_size;
5697 if (opt_super_large_pages)
5698 max_desired_page_size = SUPER_LARGE_PAGESIZE;
5699 else
5700 max_desired_page_size = LARGE_PAGESIZE;
5701 nelem = getpagesizes(NULL, 0);
5702 if (nelem > 0) {
5703 size_t *pagesize = (size_t *)malloc(sizeof(size_t) * nelem);
5704 if (pagesize != NULL && getpagesizes(pagesize, nelem) > 0) {
5705 size_t max_page_size = 0;
5706 for (int i = 0; i < nelem; i++) {
5707 if (pagesize[i] > max_page_size &&
5708 pagesize[i] <= max_desired_page_size)
5709 max_page_size = pagesize[i];
5710 }
5711 free(pagesize);
5712 if (max_page_size > 0) {
5713 struct memcntl_mha mpss;
5714
5715 mpss.mha_cmd = MHA_MAPSIZE_BSSBRK;
5716 mpss.mha_pagesize = max_page_size;
5717 mpss.mha_flags = 0;
5718 memcntl(NULL, 0, MC_HAT_ADVISE, (caddr_t)&mpss, 0, 0);
5719 mpss.mha_cmd = MHA_MAPSIZE_STACK;
5720 memcntl(NULL, 0, MC_HAT_ADVISE, (caddr_t)&mpss, 0, 0);
5721 }
5722 }
5723 }
5724 }
5725 #endif /* HAVE_SOLARIS_LARGE_PAGES */
5726
5727 longlong default_value;
5728 sys_var *var;
5729 /* Calculate and update default value for thread_cache_size. */
5730
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9786 times.
9786 if ((default_value = 8 + max_connections / 100) > 100) default_value = 100;
5731
2/4
✓ Branch 0 taken 9786 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9786 times.
✗ Branch 3 not taken.
9786 var = find_static_system_variable("thread_cache_size");
5732 9786 var->update_default(default_value);
5733
5734 /* Calculate and update default value for host_cache_size. */
5735
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9785 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9786 times.
9787 if ((default_value = 128 + max_connections) > 628 &&
5736
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 (default_value = 628 + ((max_connections - 500) / 20)) > 2000)
5737 default_value = 2000;
5738
2/4
✓ Branch 0 taken 9786 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9786 times.
✗ Branch 3 not taken.
9786 var = find_static_system_variable("host_cache_size");
5739 9786 var->update_default(default_value);
5740
5741 /* Fix thread_cache_size. */
5742
3/4
✓ Branch 0 taken 9784 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9786 times.
19570 if (!thread_cache_size_specified &&
5743 9784 (Per_thread_connection_handler::max_blocked_pthreads =
5744
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9784 times.
9784 8 + max_connections / 100) > 100)
5745 Per_thread_connection_handler::max_blocked_pthreads = 100;
5746
5747 /* Fix host_cache_size. */
5748 29356 if (!host_cache_size_specified &&
5749
5/6
✓ Branch 0 taken 9784 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 9783 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 9786 times.
9787 (host_cache_size = 128 + max_connections) > 628 &&
5750
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 (host_cache_size = 628 + ((max_connections - 500) / 20)) > 2000)
5751 host_cache_size = 2000;
5752
5753 /* Fix back_log */
5754
4/6
✓ Branch 0 taken 9783 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9783 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 9786 times.
9786 if (back_log == 0 && (back_log = max_connections) > 65535) back_log = 65535;
5755
5756 9786 unireg_init(opt_specialflag); /* Set up extern variables */
5757 9786 while (!(my_default_lc_messages =
5758
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9786 times.
9788 my_locale_by_name(nullptr, lc_messages, strlen(lc_messages)))) {
5759
7/14
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
2 LogErr(ERROR_LEVEL, ER_FAILED_TO_FIND_LOCALE_NAME, lc_messages);
5760
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!my_strcasecmp(&my_charset_latin1, lc_messages,
5761 mysqld_default_locale_name))
5762 return 1;
5763 2 lc_messages = mysqld_default_locale_name;
5764 }
5765 9786 global_system_variables.lc_messages = my_default_lc_messages;
5766
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9786 times.
9786 if (init_errmessage()) /* Read error messages from file */
5767 return 1;
5768 9786 init_client_errs();
5769
5770 9786 mysql_client_plugin_init();
5771
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9786 times.
9786 if (item_create_init()) return 1;
5772 9786 item_init();
5773 9786 range_optimizer_init();
5774 9786 my_string_stack_guard = check_enough_stack_size;
5775 /*
5776 Process a comma-separated character set list and choose
5777 the first available character set. This is mostly for
5778 test purposes, to be able to start "mysqld" even if
5779 the requested character set is not available (see bug#18743).
5780 */
5781 for (;;) {
5782 char *next_character_set_name =
5783 9786 strchr(const_cast<char *>(default_character_set_name), ',');
5784
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9784 times.
9786 if (next_character_set_name) *next_character_set_name++ = '\0';
5785
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9785 times.
9786 if (!(default_charset_info = get_charset_by_csname(
5786 default_character_set_name, MY_CS_PRIMARY, MYF(MY_WME)))) {
5787
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (next_character_set_name) {
5788 default_character_set_name = next_character_set_name;
5789 default_collation_name = nullptr; // Ignore collation
5790 } else
5791 1 return 1; // Eof of the list
5792 } else {
5793 9785 warn_on_deprecated_charset(nullptr, default_charset_info,
5794 default_character_set_name,
5795 "--character-set-server");
5796 9785 break;
5797 }
5798 }
5799
5800
2/2
✓ Branch 0 taken 9766 times.
✓ Branch 1 taken 19 times.
9785 if (default_collation_name) {
5801 CHARSET_INFO *default_collation;
5802 9766 default_collation = get_charset_by_name(default_collation_name, MYF(0));
5803
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9766 times.
9766 if (!default_collation) {
5804 LogErr(ERROR_LEVEL, ER_FAILED_TO_FIND_COLLATION_NAME,
5805 default_collation_name);
5806 return 1;
5807 }
5808
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9766 times.
9766 if (!my_charset_same(default_charset_info, default_collation)) {
5809 LogErr(ERROR_LEVEL, ER_INVALID_COLLATION_FOR_CHARSET,
5810 default_collation_name, default_charset_info->csname);
5811 return 1;
5812 }
5813 9766 warn_on_deprecated_collation(nullptr, default_collation,
5814 "--collation-server");
5815 9766 default_charset_info = default_collation;
5816 }
5817 /* Set collactions that depends on the default collation */
5818 9785 global_system_variables.collation_server = default_charset_info;
5819 9785 global_system_variables.collation_database = default_charset_info;
5820 9785 global_system_variables.default_collation_for_utf8mb4 =
5821 &my_charset_utf8mb4_0900_ai_ci;
5822
5823
2/2
✓ Branch 0 taken 9771 times.
✓ Branch 1 taken 14 times.
9785 if (is_supported_parser_charset(default_charset_info)) {
5824 9771 global_system_variables.collation_connection = default_charset_info;
5825 9771 global_system_variables.character_set_results = default_charset_info;
5826 9771 global_system_variables.character_set_client = default_charset_info;
5827 } else {
5828
7/14
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 14 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 14 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 14 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 14 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 14 times.
✗ Branch 13 not taken.
14 LogErr(INFORMATION_LEVEL, ER_FIXING_CLIENT_CHARSET,
5829 default_charset_info->csname, my_charset_latin1.csname);
5830 14 global_system_variables.collation_connection = &my_charset_latin1;
5831 14 global_system_variables.character_set_results = &my_charset_latin1;
5832 14 global_system_variables.character_set_client = &my_charset_latin1;
5833 }
5834
5835
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9785 times.
9785 if (!(character_set_filesystem = get_charset_by_csname(
5836 character_set_filesystem_name, MY_CS_PRIMARY, MYF(MY_WME))))
5837 return 1;
5838 else
5839 9785 warn_on_deprecated_charset(nullptr, character_set_filesystem,
5840 character_set_filesystem_name,
5841 "--character-set-filesystem");
5842 9785 global_system_variables.character_set_filesystem = character_set_filesystem;
5843
5844
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9785 times.
9785 if (lex_init()) {
5845 LogErr(ERROR_LEVEL, ER_OOM);
5846 return 1;
5847 }
5848
5849
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9785 times.
9787 while (!(my_default_lc_time_names = my_locale_by_name(
5850 nullptr, lc_time_names_name, strlen(lc_time_names_name)))) {
5851
7/14
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
2 LogErr(ERROR_LEVEL, ER_FAILED_TO_FIND_LOCALE_NAME, lc_time_names_name);
5852
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!my_strcasecmp(&my_charset_latin1, lc_time_names_name,
5853 mysqld_default_locale_name))
5854 return 1;
5855 2 lc_time_names_name = mysqld_default_locale_name;
5856 }
5857 9785 global_system_variables.lc_time_names = my_default_lc_time_names;
5858
5859 /* check log options and issue warnings if needed */
5860
3/4
✓ Branch 0 taken 9018 times.
✓ Branch 1 taken 767 times.
✓ Branch 2 taken 9018 times.
✗ Branch 3 not taken.
9785 if (opt_general_log && opt_general_logname &&
5861
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9018 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9018 !(log_output_options & LOG_FILE) && !(log_output_options & LOG_NONE))
5862 LogErr(WARNING_LEVEL, ER_LOG_FILES_GIVEN_LOG_OUTPUT_IS_TABLE,
5863 "--general-log-file option");
5864
5865
4/6
✓ Branch 0 taken 9018 times.
✓ Branch 1 taken 767 times.
✓ Branch 2 taken 9018 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9018 times.
9785 if (opt_slow_log && opt_slow_logname && !(log_output_options & LOG_FILE) &&
5866 !(log_output_options & LOG_NONE))
5867 LogErr(WARNING_LEVEL, ER_LOG_FILES_GIVEN_LOG_OUTPUT_IS_TABLE,
5868 "--slow-query-log-file option");
5869
5870
3/4
✓ Branch 0 taken 9333 times.
✓ Branch 1 taken 452 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9785 times.
19118 if (opt_general_logname &&
5871
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9333 times.
9333 !is_valid_log_name(opt_general_logname, strlen(opt_general_logname))) {
5872 LogErr(ERROR_LEVEL, ER_LOG_FILE_INVALID, "--general_log_file",
5873 opt_general_logname);
5874 return 1;
5875 }
5876
5877
3/4
✓ Branch 0 taken 9333 times.
✓ Branch 1 taken 452 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9785 times.
19118 if (opt_slow_logname &&
5878
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9333 times.
9333 !is_valid_log_name(opt_slow_logname, strlen(opt_slow_logname))) {
5879 LogErr(ERROR_LEVEL, ER_LOG_FILE_INVALID, "--slow_query_log_file",
5880 opt_slow_logname);
5881 return 1;
5882 }
5883
5884
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 9781 times.
9785 if (global_system_variables.transaction_write_set_extraction ==
5885 4 HASH_ALGORITHM_OFF &&
5886
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 mysql_bin_log.m_dependency_tracker.m_opt_tracking_mode !=
5887 DEPENDENCY_TRACKING_COMMIT_ORDER) {
5888
7/14
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
2 LogErr(ERROR_LEVEL,
5889 ER_TX_EXTRACTION_ALGORITHM_FOR_BINLOG_TX_DEPEDENCY_TRACKING,
5890 "XXHASH64 or MURMUR32", "WRITESET or WRITESET_SESSION");
5891 2 return 1;
5892 } else
5893 9783 mysql_bin_log.m_dependency_tracker.tracking_mode_changed();
5894
5895 #define FIX_LOG_VAR(VAR, ALT) \
5896 if (!VAR || !*VAR) VAR = ALT;
5897
5898
3/4
✓ Branch 0 taken 9331 times.
✓ Branch 1 taken 452 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9331 times.
9783 FIX_LOG_VAR(opt_general_logname,
5899 make_query_log_name(logname_path, QUERY_LOG_GENERAL));
5900
3/4
✓ Branch 0 taken 9331 times.
✓ Branch 1 taken 452 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9331 times.
9783 FIX_LOG_VAR(opt_slow_logname,
5901 my_strdup(key_memory_LOG_name,
5902 make_query_log_name(slow_logname_path, QUERY_LOG_SLOW),
5903 MYF(MY_WME)));
5904
5905 #if defined(ENABLED_DEBUG_SYNC)
5906 /* Initialize the debug sync facility. See debug_sync.cc. */
5907
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9783 times.
9783 if (debug_sync_init()) return 1; /* purecov: tested */
5908 #endif /* defined(ENABLED_DEBUG_SYNC) */
5909
5910
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 9778 times.
9783 if (opt_validate_config) return 0;
5911
5912 /* create the data directory if requested */
5913
4/4
✓ Branch 0 taken 213 times.
✓ Branch 1 taken 9565 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 9776 times.
9991 if (unlikely(opt_initialize) &&
5914
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 211 times.
213 initialize_create_data_directory(mysql_real_data_home))
5915 2 return 1;
5916
5917 /*
5918 Ensure that lower_case_table_names is set on system where we have case
5919 insensitive names. If this is not done the users MyISAM tables will
5920 get corrupted if accesses with names of different case.
5921 */
5922
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9776 times.
9776 DBUG_PRINT("info", ("lower_case_table_names: %d", lower_case_table_names));
5923 9776 lower_case_file_system =
5924 9776 (test_if_case_insensitive(mysql_real_data_home) == 1);
5925
3/4
✓ Branch 0 taken 9614 times.
✓ Branch 1 taken 162 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9614 times.
9776 if (!lower_case_table_names && lower_case_file_system) {
5926 if (lower_case_table_names_used) {
5927 LogErr(ERROR_LEVEL, ER_LOWER_CASE_TABLE_NAMES_CS_DD_ON_CI_FS_UNSUPPORTED);
5928 return 1;
5929 } else {
5930 LogErr(WARNING_LEVEL, ER_LOWER_CASE_TABLE_NAMES_USING_2,
5931 mysql_real_data_home);
5932 lower_case_table_names = 2;
5933 }
5934
3/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 9765 times.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
9776 } else if (lower_case_table_names == 2 && !lower_case_file_system) {
5935
7/14
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 11 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 11 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 11 times.
✗ Branch 13 not taken.
11 LogErr(WARNING_LEVEL, ER_LOWER_CASE_TABLE_NAMES_USING_0,
5936 mysql_real_data_home);
5937 11 lower_case_table_names = 0;
5938 }
5939
5940 /* Reset table_alias_charset, now that lower_case_table_names is set. */
5941 9776 table_alias_charset =
5942
2/2
✓ Branch 0 taken 151 times.
✓ Branch 1 taken 9625 times.
9776 (lower_case_table_names ? &my_charset_utf8_tolower_ci : &my_charset_bin);
5943
5944 /*
5945 Build do_table and ignore_table rules to hashes
5946 after the resetting of table_alias_charset.
5947 */
5948
2/4
✓ Branch 0 taken 9776 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9776 times.
19552 if (rpl_global_filter.build_do_table_hash() ||
5949
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9776 times.
9776 rpl_global_filter.build_ignore_table_hash()) {
5950 LogErr(ERROR_LEVEL, ER_CANT_HASH_DO_AND_IGNORE_RULES);
5951 return 1;
5952 }
5953
5954 /*
5955 Reset the P_S view for global replication filter at
5956 the end of server startup.
5957 */
5958 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
5959 9776 rpl_global_filter.wrlock();
5960 9776 rpl_global_filter.reset_pfs_view();
5961 9776 rpl_global_filter.unlock();
5962 #endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
5963
5964
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9776 times.
9776 if (rpl_channel_filters.build_do_and_ignore_table_hashes()) return 1;
5965
5966 9776 return 0;
5967 }
5968
5969 9824 static int init_thread_environment() {
5970 9824 mysql_mutex_init(key_LOCK_status, &LOCK_status, MY_MUTEX_INIT_FAST);
5971 9824 mysql_mutex_init(key_LOCK_manager, &LOCK_manager, MY_MUTEX_INIT_FAST);
5972 9824 mysql_mutex_init(key_LOCK_crypt, &LOCK_crypt, MY_MUTEX_INIT_FAST);
5973 9824 mysql_mutex_init(key_LOCK_user_conn, &LOCK_user_conn, MY_MUTEX_INIT_FAST);
5974 9824 mysql_mutex_init(key_LOCK_global_system_variables,
5975 &LOCK_global_system_variables, MY_MUTEX_INIT_FAST);
5976 9824 mysql_rwlock_init(key_rwlock_LOCK_system_variables_hash,
5977 &LOCK_system_variables_hash);
5978 9824 mysql_mutex_init(key_LOCK_prepared_stmt_count, &LOCK_prepared_stmt_count,
5979 MY_MUTEX_INIT_FAST);
5980 9824 mysql_mutex_init(key_LOCK_replica_list, &LOCK_replica_list,
5981 MY_MUTEX_INIT_FAST);
5982 9824 mysql_mutex_init(key_LOCK_sql_replica_skip_counter,
5983 &LOCK_sql_replica_skip_counter, MY_MUTEX_INIT_FAST);
5984 9824 mysql_mutex_init(key_LOCK_replica_net_timeout, &LOCK_replica_net_timeout,
5985 MY_MUTEX_INIT_FAST);
5986 9824 mysql_mutex_init(key_LOCK_replica_trans_dep_tracker,
5987 &LOCK_replica_trans_dep_tracker, MY_MUTEX_INIT_FAST);
5988 9824 mysql_mutex_init(key_LOCK_error_messages, &LOCK_error_messages,
5989 MY_MUTEX_INIT_FAST);
5990 9824 mysql_mutex_init(key_LOCK_uuid_generator, &LOCK_uuid_generator,
5991 MY_MUTEX_INIT_FAST);
5992 9824 mysql_mutex_init(key_LOCK_sql_rand, &LOCK_sql_rand, MY_MUTEX_INIT_FAST);
5993 9824 mysql_mutex_init(key_LOCK_log_throttle_qni, &LOCK_log_throttle_qni,
5994 MY_MUTEX_INIT_FAST);
5995 9824 mysql_mutex_init(key_LOCK_default_password_lifetime,
5996 &LOCK_default_password_lifetime, MY_MUTEX_INIT_FAST);
5997 9824 mysql_mutex_init(key_LOCK_mandatory_roles, &LOCK_mandatory_roles,
5998 MY_MUTEX_INIT_FAST);
5999 9824 mysql_mutex_init(key_LOCK_password_history, &LOCK_password_history,
6000 MY_MUTEX_INIT_FAST);
6001 9824 mysql_mutex_init(key_LOCK_password_reuse_interval,
6002 &LOCK_password_reuse_interval, MY_MUTEX_INIT_FAST);
6003 9824 mysql_rwlock_init(key_rwlock_LOCK_sys_init_connect, &LOCK_sys_init_connect);
6004 9824 mysql_rwlock_init(key_rwlock_LOCK_sys_init_replica, &LOCK_sys_init_replica);
6005 9824 mysql_cond_init(key_COND_manager, &COND_manager);
6006 9824 mysql_mutex_init(key_LOCK_server_started, &LOCK_server_started,
6007 MY_MUTEX_INIT_FAST);
6008 9824 mysql_cond_init(key_COND_server_started, &COND_server_started);
6009 9824 mysql_mutex_init(key_LOCK_reset_gtid_table, &LOCK_reset_gtid_table,
6010 MY_MUTEX_INIT_FAST);
6011 9824 mysql_mutex_init(key_LOCK_compress_gtid_table, &LOCK_compress_gtid_table,
6012 MY_MUTEX_INIT_FAST);
6013 9824 mysql_mutex_init(key_LOCK_collect_instance_log, &LOCK_collect_instance_log,
6014 MY_MUTEX_INIT_FAST);
6015 9824 mysql_cond_init(key_COND_compress_gtid_table, &COND_compress_gtid_table);
6016
6017 9824 mysql_mutex_init(key_LOCK_global_user_client_stats,
6018 &LOCK_global_user_client_stats, MY_MUTEX_INIT_FAST);
6019 9824 mysql_mutex_init(key_LOCK_global_table_stats, &LOCK_global_table_stats,
6020 MY_MUTEX_INIT_FAST);
6021 9824 mysql_mutex_init(key_LOCK_global_index_stats, &LOCK_global_index_stats,
6022 MY_MUTEX_INIT_FAST);
6023
6024 9824 Events::init_mutexes();
6025 #if defined(_WIN32)
6026 mysql_mutex_init(key_LOCK_handler_count, &LOCK_handler_count,
6027 MY_MUTEX_INIT_FAST);
6028 mysql_cond_init(key_COND_handler_count, &COND_handler_count);
6029 mysql_rwlock_init(key_rwlock_LOCK_named_pipe_full_access_group,
6030 &LOCK_named_pipe_full_access_group);
6031 #else
6032 9824 mysql_mutex_init(key_LOCK_socket_listener_active,
6033 &LOCK_socket_listener_active, MY_MUTEX_INIT_FAST);
6034 9824 mysql_cond_init(key_COND_socket_listener_active,
6035 &COND_socket_listener_active);
6036 9824 mysql_mutex_init(key_LOCK_start_signal_handler, &LOCK_start_signal_handler,
6037 MY_MUTEX_INIT_FAST);
6038 9824 mysql_cond_init(key_COND_start_signal_handler, &COND_start_signal_handler);
6039 #endif // _WIN32
6040 /* Parameter for threads created for connections */
6041 9824 (void)my_thread_attr_init(&connection_attrib);
6042 9824 my_thread_attr_setdetachstate(&connection_attrib, MY_THREAD_CREATE_DETACHED);
6043 #ifndef _WIN32
6044 9824 pthread_attr_setscope(&connection_attrib, PTHREAD_SCOPE_SYSTEM);
6045 #endif
6046
6047 9824 mysql_mutex_init(key_LOCK_keyring_operations, &LOCK_keyring_operations,
6048 MY_MUTEX_INIT_FAST);
6049 9824 mysql_mutex_init(key_LOCK_tls_ctx_options, &LOCK_tls_ctx_options,
6050 MY_MUTEX_INIT_FAST);
6051 9824 mysql_mutex_init(key_LOCK_rotate_binlog_master_key,
6052 &LOCK_rotate_binlog_master_key, MY_MUTEX_INIT_FAST);
6053 9824 mysql_mutex_init(key_LOCK_admin_tls_ctx_options, &LOCK_admin_tls_ctx_options,
6054 MY_MUTEX_INIT_FAST);
6055 9824 mysql_mutex_init(key_LOCK_partial_revokes, &LOCK_partial_revokes,
6056 MY_MUTEX_INIT_FAST);
6057 9824 mysql_mutex_init(key_LOCK_authentication_policy, &LOCK_authentication_policy,
6058 MY_MUTEX_INIT_FAST);
6059 9824 mysql_mutex_init(key_LOCK_global_conn_mem_limit, &LOCK_global_conn_mem_limit,
6060 MY_MUTEX_INIT_FAST);
6061 #ifdef WITH_WSREP
6062 9824 mysql_mutex_init(key_LOCK_wsrep_ready, &LOCK_wsrep_ready, MY_MUTEX_INIT_FAST);
6063 9824 mysql_cond_init(key_COND_wsrep_ready, &COND_wsrep_ready);
6064 9824 mysql_mutex_init(key_LOCK_wsrep_sst, &LOCK_wsrep_sst, MY_MUTEX_INIT_FAST);
6065 9824 mysql_cond_init(key_COND_wsrep_sst, &COND_wsrep_sst);
6066 9824 mysql_mutex_init(key_LOCK_wsrep_sst_init, &LOCK_wsrep_sst_init,
6067 MY_MUTEX_INIT_FAST);
6068 9824 mysql_cond_init(key_COND_wsrep_sst_init, &COND_wsrep_sst_init);
6069 9824 mysql_mutex_init(key_LOCK_wsrep_replaying, &LOCK_wsrep_replaying,
6070 MY_MUTEX_INIT_FAST);
6071 9824 mysql_cond_init(key_COND_wsrep_replaying, &COND_wsrep_replaying);
6072 9824 mysql_mutex_init(key_LOCK_wsrep_slave_threads, &LOCK_wsrep_slave_threads,
6073 MY_MUTEX_INIT_FAST);
6074 9824 mysql_cond_init(key_COND_wsrep_slave_threads, &COND_wsrep_slave_threads);
6075 9824 mysql_mutex_init(key_LOCK_wsrep_cluster_config, &LOCK_wsrep_cluster_config,
6076 MY_MUTEX_INIT_FAST);
6077 9824 mysql_mutex_init(key_LOCK_wsrep_desync, &LOCK_wsrep_desync,
6078 MY_MUTEX_INIT_FAST);
6079 9824 mysql_mutex_init(key_LOCK_wsrep_group_commit, &LOCK_wsrep_group_commit,
6080 MY_MUTEX_INIT_FAST);
6081 9824 mysql_cond_init(key_COND_wsrep_group_commit, &COND_wsrep_group_commit);
6082 9824 mysql_mutex_init(key_LOCK_wsrep_SR_pool, &LOCK_wsrep_SR_pool,
6083 MY_MUTEX_INIT_FAST);
6084 9824 mysql_mutex_init(key_LOCK_wsrep_SR_store, &LOCK_wsrep_SR_store,
6085 MY_MUTEX_INIT_FAST);
6086 9824 mysql_mutex_init(key_LOCK_wsrep_alter_tablespace,
6087 &LOCK_wsrep_alter_tablespace, MY_MUTEX_INIT_FAST);
6088 #endif /* WITH_WSREP */
6089 9824 return 0;
6090 }
6091
6092 static PSI_memory_key key_memory_openssl = PSI_NOT_INSTRUMENTED;
6093
6094 #if OPENSSL_VERSION_NUMBER < 0x10100000L
6095 #define FILE_LINE_ARGS
6096 #else
6097 #define FILE_LINE_ARGS , const char *, int
6098 #endif
6099
6100 113547543 static void *my_openssl_malloc(size_t size FILE_LINE_ARGS) {
6101 113547543 return my_malloc(key_memory_openssl, size, MYF(MY_WME));
6102 }
6103 4042419 static void *my_openssl_realloc(void *ptr, size_t size FILE_LINE_ARGS) {
6104 4042419 return my_realloc(key_memory_openssl, ptr, size, MYF(MY_WME));
6105 }
6106 157679493 static void my_openssl_free(void *ptr FILE_LINE_ARGS) { return my_free(ptr); }
6107
6108 9813 static void init_ssl() {
6109 #if defined(HAVE_PSI_MEMORY_INTERFACE)
6110 static PSI_memory_info all_openssl_memory[] = {
6111 {&key_memory_openssl, "openssl_malloc", 0, 0,
6112 "All memory used by openSSL"}};
6113 9813 mysql_memory_register("mysqld_openssl", all_openssl_memory,
6114 (int)array_elements(all_openssl_memory));
6115 #endif /* defined(HAVE_PSI_MEMORY_INTERFACE) */
6116 9813 int ret = CRYPTO_set_mem_functions(my_openssl_malloc, my_openssl_realloc,
6117 my_openssl_free);
6118
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9813 times.
9813 if (ret == 0)
6119 LogErr(WARNING_LEVEL, ER_SSL_MEMORY_INSTRUMENTATION_INIT_FAILED,
6120 "CRYPTO_set_mem_functions");
6121 9813 ssl_start();
6122 9813 }
6123
6124 9456 static int init_ssl_communication() {
6125 9456 char ssl_err_string[OPENSSL_ERROR_LENGTH] = {'\0'};
6126
3/4
✓ Branch 0 taken 9456 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 9455 times.
9456 if (set_fips_mode(opt_ssl_fips_mode, ssl_err_string)) {
6127
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(ERROR_LEVEL, ER_SSL_FIPS_MODE_ERROR, ssl_err_string);
6128 1 return 1;
6129 }
6130
4/6
✓ Branch 0 taken 9455 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9454 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 9448 times.
9455 if (TLS_channel::singleton_init(&mysql_main, mysql_main_channel, opt_use_ssl,
6131 &server_main_callback, opt_initialize))
6132 6 return 1;
6133
6134 /*
6135 The default value of --admin-ssl is ON. If it is set
6136 to off, we should treat it as an explicit attempt to
6137 set TLS off for admin channel and thereby not use
6138 main channel's TLS configuration.
6139 */
6140
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 9445 times.
9448 if (!opt_use_admin_ssl) g_admin_ssl_configured = true;
6141
6142 9448 bool initialize_admin_tls =
6143
2/2
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 9212 times.
9246 (!opt_initialize && (my_admin_bind_addr_str != nullptr))
6144
2/2
✓ Branch 0 taken 9246 times.
✓ Branch 1 taken 202 times.
18694 ? opt_use_admin_ssl
6145
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 2 times.
34 : false;
6146
6147 9448 Ssl_init_callback_server_admin server_admin_callback;
6148
3/6
✓ Branch 0 taken 9448 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9448 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9448 times.
9448 if (TLS_channel::singleton_init(&mysql_admin, mysql_admin_channel,
6149 initialize_admin_tls, &server_admin_callback,
6150 opt_initialize))
6151 return 1;
6152
6153
6/6
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 9416 times.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 20 times.
✓ Branch 5 taken 9428 times.
9448 if (initialize_admin_tls && !g_admin_ssl_configured) {
6154
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 Lock_and_access_ssl_acceptor_context context(mysql_main);
6155
3/4
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19 times.
✓ Branch 3 taken 1 times.
20 if (context.have_ssl())
6156
8/16
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 19 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 19 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 19 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 19 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 19 times.
✗ Branch 15 not taken.
19 LogErr(SYSTEM_LEVEL, ER_TLS_CONFIGURATION_REUSED,
6157 mysql_admin_channel.c_str(), mysql_main_channel.c_str());
6158 20 }
6159
6160 #if OPENSSL_VERSION_NUMBER < 0x10100000L
6161 ERR_remove_thread_state(0);
6162 #endif /* OPENSSL_VERSION_NUMBER < 0x10100000L */
6163
6164
3/4
✓ Branch 0 taken 9448 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 9445 times.
9448 if (init_rsa_keys()) return 1;
6165 9445 return 0;
6166 9448 }
6167
6168 8457 static void end_ssl() {
6169 8457 TLS_channel::singleton_deinit(mysql_main);
6170 8457 TLS_channel::singleton_deinit(mysql_admin);
6171 8457 deinit_rsa_keys();
6172 8457 }
6173
6174 /**
6175 Generate a UUID and save it into server_uuid variable.
6176
6177 @return Return 0 or 1 if an error occurred.
6178 */
6179 4634 static int generate_server_uuid() {
6180 THD *thd;
6181 Item_func_uuid *func_uuid;
6182 4634 String uuid;
6183
6184 /*
6185 To be able to run this from boot, we allocate a temporary THD,
6186 since plugins are not yet loaded we pass false to temporary THD.
6187 */
6188
3/6
✓ Branch 0 taken 4634 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4634 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4634 times.
4634 if (!(thd = new THD(false))) {
6189 LogErr(ERROR_LEVEL, ER_NO_THD_NO_UUID);
6190 return 1;
6191 }
6192 4634 thd->thread_stack = (char *)&thd;
6193
1/2
✓ Branch 0 taken 4634 times.
✗ Branch 1 not taken.
4634 thd->store_globals();
6194
6195 /*
6196 Initialize the variables which are used during "uuid generator
6197 initialization" with values that should normally differ between
6198 mysqlds on the same host. This avoids that another mysqld started
6199 at the same time on the same host get the same "server_uuid".
6200 */
6201
6202 4634 const time_t save_server_start_time = server_start_time;
6203 4634 server_start_time += ((ulonglong)current_pid << 48) + current_pid;
6204 4634 thd->status_var.bytes_sent = (ulonglong)thd;
6205
6206
1/2
✓ Branch 0 taken 4634 times.
✗ Branch 1 not taken.
4634 lex_start(thd);
6207
1/2
✓ Branch 0 taken 4634 times.
✗ Branch 1 not taken.
9268 func_uuid = new (thd->mem_root) Item_func_uuid();
6208 4634 func_uuid->fixed = true;
6209
1/2
✓ Branch 0 taken 4634 times.
✗ Branch 1 not taken.
4634 func_uuid->val_str(&uuid);
6210
6211 // Restore global variables used for salting
6212 4634 server_start_time = save_server_start_time;
6213
6214
1/2
✓ Branch 0 taken 4634 times.
✗ Branch 1 not taken.
4634 delete thd;
6215
6216
1/2
✓ Branch 0 taken 4634 times.
✗ Branch 1 not taken.
4634 strncpy(server_uuid, uuid.c_ptr(), sizeof(server_uuid));
6217
3/4
✓ Branch 0 taken 4634 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 4631 times.
4634 DBUG_EXECUTE_IF("server_uuid_deterministic",
6218 memcpy(server_uuid, "00000000-1111-0000-1111-000000000000",
6219 UUID_LENGTH););
6220 4634 server_uuid[UUID_LENGTH] = '\0';
6221 4634 return 0;
6222 4634 }
6223
6224 /**
6225 Save all options which was auto-generated by server-self into the given file.
6226
6227 @param fname The name of the file in which the auto-generated options will b
6228 e saved.
6229
6230 @return Return 0 or 1 if an error occurred.
6231 */
6232 4634 static int flush_auto_options(const char *fname) {
6233 File fd;
6234 4634 IO_CACHE io_cache;
6235 4634 int result = 0;
6236
6237
2/4
✓ Branch 0 taken 4634 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4634 times.
4634 if ((fd = my_open(fname, O_CREAT | O_RDWR, MYF(MY_WME))) < 0) {
6238 LogErr(ERROR_LEVEL, ER_AUTO_OPTIONS_FAILED, "file", fname, my_errno());
6239 return 1;
6240 }
6241
6242
2/4
✓ Branch 0 taken 4634 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4634 times.
4634 if (init_io_cache(&io_cache, fd, IO_SIZE * 2, WRITE_CACHE, 0L, false,
6243 MYF(MY_WME))) {
6244 LogErr(ERROR_LEVEL, ER_AUTO_OPTIONS_FAILED, "a cache on ", fname,
6245 my_errno());
6246 my_close(fd, MYF(MY_WME));
6247 return 1;
6248 }
6249
6250
1/2
✓ Branch 0 taken 4634 times.
✗ Branch 1 not taken.
4634 my_b_seek(&io_cache, 0L);
6251
1/2
✓ Branch 0 taken 4634 times.
✗ Branch 1 not taken.
4634 my_b_printf(&io_cache, "%s\n", "[auto]");
6252
1/2
✓ Branch 0 taken 4634 times.
✗ Branch 1 not taken.
4634 my_b_printf(&io_cache, "server-uuid=%s\n", server_uuid);
6253
6254
5/10
✓ Branch 0 taken 4634 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4634 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4634 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4634 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4634 times.
4634 if (flush_io_cache(&io_cache) || my_sync(fd, MYF(MY_WME))) result = 1;
6255
6256
1/2
✓ Branch 0 taken 4634 times.
✗ Branch 1 not taken.
4634 my_close(fd, MYF(MY_WME));
6257
1/2
✓ Branch 0 taken 4634 times.
✗ Branch 1 not taken.
4634 end_io_cache(&io_cache);
6258 4634 return result;
6259 }
6260
6261 /**
6262 File 'auto.cnf' resides in the data directory to hold values of options that
6263 server evaluates itself and that needs to be durable to sustain the server
6264 restart. There is only a section ['auto'] in the file. All these options are
6265 in the section. Only one option exists now, it is server_uuid.
6266 Note, the user may not supply any literal value to these auto-options, and
6267 only allowed to trigger (re)evaluation.
6268 For instance, 'server_uuid' value will be evaluated and stored if there is
6269 no corresponding line in the file.
6270 Because of the specifics of the auto-options, they need separate storage.
6271 Meanwhile, it is the 'auto.cnf' that has the same structure as 'my.cnf'.
6272
6273 @todo consider to implement sql-query-able persistent storage by WL#5279.
6274 @return Return 0 or 1 if an error occurred.
6275 */
6276 9734 static int init_server_auto_options() {
6277 9734 bool flush = false;
6278 char fname[FN_REFLEN];
6279 9734 char name[] = "auto";
6280 9734 char *name_ptr = name;
6281 9734 const char *groups[] = {"auto", nullptr};
6282 9734 char *uuid = nullptr;
6283 9734 my_option auto_options[] = {
6284 {"server-uuid", 0, "", &uuid, &uuid, nullptr, GET_STR, REQUIRED_ARG, 0, 0,
6285 0, nullptr, 0, nullptr},
6286 {nullptr, 0, nullptr, nullptr, nullptr, nullptr, GET_NO_ARG, NO_ARG, 0, 0,
6287 9734 0, nullptr, 0, nullptr}};
6288
6289
1/2
✓ Branch 0 taken 9734 times.
✗ Branch 1 not taken.
9734 DBUG_TRACE;
6290
6291
2/4
✓ Branch 0 taken 9734 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9734 times.
9734 if (nullptr == fn_format(fname, "auto.cnf", mysql_real_data_home_ptr, "",
6292 MY_UNPACK_FILENAME | MY_SAFE_PATH))
6293 return 1;
6294
6295 /* load_defaults require argv[0] is not null */
6296 9734 char **argv = &name_ptr;
6297 9734 int argc = 1;
6298
3/4
✓ Branch 0 taken 9734 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 9733 times.
9734 if (!check_file_permissions(fname, false)) {
6299 /*
6300 Found a world writable file hence removing it as it is dangerous to write
6301 a new UUID into the same file.
6302 */
6303
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 my_delete(fname, MYF(MY_WME));
6304
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(WARNING_LEVEL, ER_WRITABLE_CONFIG_REMOVED, fname);
6305 }
6306
6307 /* load all options in 'auto.cnf'. */
6308 9734 MEM_ROOT alloc{PSI_NOT_INSTRUMENTED, 512};
6309
2/4
✓ Branch 0 taken 9734 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9734 times.
9734 if (my_load_defaults(fname, groups, &argc, &argv, &alloc, nullptr)) return 1;
6310
6311
2/4
✓ Branch 0 taken 9734 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9734 times.
9734 if (handle_options(&argc, &argv, auto_options, mysqld_get_one_option))
6312 return 1;
6313
6314
3/8
✓ Branch 0 taken 9734 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9734 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9734 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
9734 DBUG_PRINT("info", ("uuid=%p=%s server_uuid=%s", uuid, uuid, server_uuid));
6315
2/2
✓ Branch 0 taken 5100 times.
✓ Branch 1 taken 4634 times.
9734 if (uuid) {
6316
2/4
✓ Branch 0 taken 5100 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5100 times.
5100 if (!binary_log::Uuid::is_valid(uuid, binary_log::Uuid::TEXT_LENGTH)) {
6317 LogErr(ERROR_LEVEL, ER_UUID_INVALID);
6318 goto err;
6319 }
6320 /*
6321 Uuid::is_valid() cannot do strict check on the length as it will be
6322 called by GTID::is_valid() as well (GTID = UUID:seq_no). We should
6323 explicitly add the *length check* here in this function.
6324
6325 If UUID length is less than '36' (UUID_LENGTH), that error case would have
6326 got caught in above is_valid check. The below check is to make sure that
6327 length is not greater than UUID_LENGTH i.e., there are no extra characters
6328 (Garbage) at the end of the valid UUID.
6329 */
6330
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5100 times.
5100 if (strlen(uuid) > UUID_LENGTH) {
6331 LogErr(ERROR_LEVEL, ER_UUID_SCRUB, UUID_LENGTH);
6332 goto err;
6333 }
6334 5100 strcpy(server_uuid, uuid);
6335 } else {
6336
3/8
✓ Branch 0 taken 4634 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4634 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4634 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
4634 DBUG_PRINT("info", ("generating server_uuid"));
6337 4634 flush = true;
6338 /* server_uuid will be set in the function */
6339
2/4
✓ Branch 0 taken 4634 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4634 times.
4634 if (generate_server_uuid()) goto err;
6340
3/8
✓ Branch 0 taken 4634 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4634 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4634 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
4634 DBUG_PRINT("info", ("generated server_uuid=%s", server_uuid));
6341
3/4
✓ Branch 0 taken 4424 times.
✓ Branch 1 taken 210 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4424 times.
4634 if (opt_initialize || opt_initialize_insecure) {
6342
8/16
✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 210 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 210 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 210 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 210 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 210 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 210 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 210 times.
✗ Branch 15 not taken.
210 LogErr(INFORMATION_LEVEL, ER_CREATING_NEW_UUID_FIRST_START, server_uuid);
6343
6344 } else {
6345
8/16
✓ Branch 0 taken 4424 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4424 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4424 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4424 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4424 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4424 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 4424 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 4424 times.
✗ Branch 15 not taken.
4424 LogErr(WARNING_LEVEL, ER_CREATING_NEW_UUID, server_uuid);
6346 }
6347 }
6348
6349
3/4
✓ Branch 0 taken 4634 times.
✓ Branch 1 taken 5100 times.
✓ Branch 2 taken 4634 times.
✗ Branch 3 not taken.
9734 if (flush) return flush_auto_options(fname);
6350 5100 return 0;
6351 err:
6352 return 1;
6353 9734 }
6354
6355 19150 static bool initialize_storage_engine(const char *se_name, const char *se_kind,
6356 plugin_ref *dest_plugin) {
6357 19150 LEX_CSTRING name = {se_name, strlen(se_name)};
6358 plugin_ref plugin;
6359 handlerton *hton;
6360
2/4
✓ Branch 0 taken 19150 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19150 times.
✗ Branch 3 not taken.
19150 if ((plugin = ha_resolve_by_name(nullptr, &name, false)))
6361 19150 hton = plugin_data<handlerton *>(plugin);
6362 else {
6363 LogErr(ERROR_LEVEL, ER_UNKNOWN_UNSUPPORTED_STORAGE_ENGINE, se_name);
6364 return true;
6365 }
6366
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19150 times.
19150 if (!ha_storage_engine_is_enabled(hton)) {
6367 if (!opt_initialize) {
6368 LogErr(ERROR_LEVEL, ER_DEFAULT_SE_UNAVAILABLE, se_kind, se_name);
6369 return true;
6370 }
6371 assert(*dest_plugin);
6372 } else {
6373 /*
6374 Need to unlock as global_system_variables.table_plugin
6375 was acquired during plugin_register_builtin_and_init_core_se()
6376 */
6377 19150 plugin_ref old_dest_plugin = *dest_plugin;
6378 19150 *dest_plugin = plugin;
6379
1/2
✓ Branch 0 taken 19150 times.
✗ Branch 1 not taken.
19150 plugin_unlock(nullptr, old_dest_plugin);
6380 }
6381 19150 return false;
6382 }
6383
6384 9802 static void setup_error_log() {
6385 /* Setup logs */
6386
6387 /*
6388 Enable old-fashioned error log, except when the user has requested
6389 help information. Since the implementation of plugin server
6390 variables the help output is now written much later.
6391
6392 log_error_dest can be:
6393 disabled_my_option --log-error was not used or --log-error=
6394 "" --log-error without arguments (no '=')
6395 filename --log-error=filename
6396 */
6397
6398 #ifdef _WIN32
6399 /*
6400 Enable the error log file only if console option is not specified
6401 and --help is not used.
6402 */
6403 bool log_errors_to_file = !is_help_or_validate_option() && !opt_console;
6404 #else
6405 /*
6406 Enable the error log file only if --log-error=filename or --log-error
6407 was used. Logging to file is disabled by default unlike on Windows.
6408 */
6409 bool log_errors_to_file =
6410
4/4
✓ Branch 0 taken 9783 times.
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 1129 times.
✓ Branch 3 taken 8654 times.
9802 !is_help_or_validate_option() && (log_error_dest != disabled_my_option);
6411 #endif
6412
6413
2/2
✓ Branch 0 taken 1129 times.
✓ Branch 1 taken 8673 times.
9802 if (log_errors_to_file) {
6414 // Construct filename if no filename was given by the user.
6415
3/4
✓ Branch 0 taken 1127 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1127 times.
1129 if (!log_error_dest[0] || log_error_dest == disabled_my_option) {
6416 #ifdef _WIN32
6417 const char *filename = pidfile_name;
6418 #else
6419 2 const char *filename = default_logfile_name;
6420 #endif
6421 2 fn_format(errorlog_filename_buff, filename, mysql_real_data_home, ".err",
6422 MY_REPLACE_EXT | /* replace '.<domain>' by '.err', bug#4997 */
6423 MY_REPLACE_DIR);
6424 2 } else
6425 1127 fn_format(errorlog_filename_buff, log_error_dest, mysql_data_home, ".err",
6426 MY_UNPACK_FILENAME);
6427 /*
6428 log_error_dest may have been set to disabled_my_option or "" if no
6429 argument was passed, but we need to show the real name in SHOW VARIABLES.
6430 */
6431 1129 log_error_dest = errorlog_filename_buff;
6432
6433 #ifndef _WIN32
6434 // Create backup stream to stdout if daemonizing and connected to tty
6435
4/6
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1127 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1129 times.
1129 if (opt_daemonize && isatty(STDOUT_FILENO)) {
6436 nstdout = fdopen(dup(STDOUT_FILENO), "a");
6437 if (nstdout == nullptr) {
6438 LogErr(ERROR_LEVEL, ER_DUP_FD_OPEN_FAILED, "stdout", strerror(errno));
6439 unireg_abort(MYSQLD_ABORT_EXIT);
6440 }
6441 // Display location of error log file on stdout if connected to tty
6442 fprintf(nstdout, "mysqld will log errors to %s\n",
6443 errorlog_filename_buff);
6444 }
6445 #endif /* ndef _WIN32 */
6446
6447
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1127 times.
1129 if (open_error_log(errorlog_filename_buff, false))
6448 2 unireg_abort(MYSQLD_ABORT_EXIT);
6449
6450 #ifdef _WIN32
6451 // FreeConsole(); // Remove window
6452 #endif /* _WIN32 */
6453 } else {
6454 // We are logging to stderr and SHOW VARIABLES should reflect that.
6455 8673 log_error_dest = "stderr";
6456 }
6457 9800 }
6458
6459 /**
6460 Try to set the error logging pipeline from @@global.log_error_services.
6461 Try to read the previous run's error log and make it available in
6462 performance_schema.error_log.
6463 Flush the buffered error messages to performance schema and to configured
6464 services, and end error log buffering.
6465 On success, log_error_stage_current becomes
6466 LOG_ERROR_STAGE_COMPONENTS_AND_PFS.
6467
6468 @retval 0 Success
6469 @retval 1 Log pipeline not set up as requested. Caller should abort.
6470 */
6471 9757 static int setup_error_log_components() {
6472 9757 int ret = 1; // failure unless otherwise specified
6473
6474 /*
6475 LOCK_plugin needs to be valid in case we implicitly load
6476 components below that install component-variables.
6477 (Otherwise, an assert will fire as the variable-install
6478 code examines the locks, but plugins have not yet been
6479 initialized.)
6480 */
6481 9757 mysql_mutex_init(0, &LOCK_plugin, MY_MUTEX_INIT_FAST);
6482
6483 /*
6484 Now that we have the component infrastructure, check
6485 --log-error-services=... -- is it well-formed, and do
6486 the requested services exist?
6487 As a side-effect, this will load any external logging
6488 components listed.
6489 This way when we run get_options(), any system variables
6490 provided by those logging components will already be
6491 available.
6492
6493 This function loads its components directly without
6494 going through the layer that persists component set-up
6495 in mysql.component. This way, our logging components can
6496 be activated before rather than after InnoDB becomes
6497 available, and InnoDB start-up messages can be logged
6498 using components as a result.
6499 */
6500
2/2
✓ Branch 0 taken 9755 times.
✓ Branch 1 taken 2 times.
9757 if (log_builtins_error_stack(opt_log_error_services, true, nullptr) == 0) {
6501 // Syntax is OK and services exist; let's try to initialize them:
6502 size_t pos;
6503
6504
2/4
✓ Branch 0 taken 9755 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9755 times.
9755 if (log_builtins_error_stack(opt_log_error_services, false, &pos) < 0) {
6505 char *problem = opt_log_error_services; /* purecov: begin inspected */
6506 const std::string var_name = "log_error_services";
6507
6508 /*
6509 We failed to set the requested configuration. This can happen
6510 e.g. when a given log-writer does not have sufficient permissions
6511 to open its log files. pos should mark the position in the
6512 configuration string where we ran into trouble. Make a char-pointer
6513 from it so we can inform the user what log-service we could not
6514 initialize.
6515 */
6516 if (pos < strlen(opt_log_error_services))
6517 problem = &((char *)opt_log_error_services)[pos];
6518
6519 /*
6520 We could not set the requested pipeline.
6521 Try to fall back to default error logging stack
6522 (by looking up the system variable for this configuration
6523 item and extracting the default value from it).
6524 If that's impossible, print diagnostics, then exit.
6525 */
6526 sys_var *var = find_static_system_variable(var_name);
6527
6528 if (var != nullptr) {
6529 // We found the system variable, now extract the default value:
6530 opt_log_error_services = (char *)var->get_default();
6531 if (log_builtins_error_stack(opt_log_error_services, false, nullptr) >=
6532 0) {
6533 /*
6534 We managed to set the default pipeline. Now log what was wrong
6535 about the user-supplied value, then shut down.
6536 */
6537 flush_error_log_messages();
6538 LogErr(ERROR_LEVEL, ER_CANT_START_ERROR_LOG_SERVICE, var_name.c_str(),
6539 problem);
6540 goto failure;
6541 }
6542 /*
6543 If we arrive here, the user-supplied value was valid, but could
6544 not be set. The default value was found, but also could not be
6545 set. Something is very wrong. Fall-through to below where we
6546 low-level write diagnostics, then abort.
6547 */
6548 }
6549
6550 /*
6551 We failed to set the default error logging stack (or failed to look
6552 up the default setting). At this point, we don't know whether ANY of
6553 the requested sinks work, so our best bet is to write directly to the
6554 error stream. Then, we abort.
6555 */
6556 {
6557 char buff[512];
6558 size_t len;
6559
6560 len = snprintf(buff, sizeof(buff),
6561 ER_DEFAULT(ER_CANT_START_ERROR_LOG_SERVICE),
6562 var_name.c_str(), problem);
6563 len = std::min(len, sizeof(buff) - 1);
6564
6565 // Trust nothing. Write directly. Quit.
6566 log_write_errstream(buff, len);
6567
6568 goto failure;
6569 } /* purecov: end */
6570 } // value was OK, but could not be set
6571 // If we arrive here, the value was OK, and was set successfully.
6572 } else {
6573 /*
6574 We were given an illegal value at start-up, so the default was
6575 used instead. Let's now point our variable back at the default
6576 (i.e. the value actually used) so SELECT @@GLOBAL.log_error_services
6577 will render correct results.
6578 */
6579
6580
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 sys_var *var = find_static_system_variable("log_error_services");
6581 2 char *default_services = nullptr;
6582
6583
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 if ((var != nullptr) &&
6584
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 ((default_services = (char *)var->get_default()) != nullptr))
6585 2 log_builtins_error_stack(default_services, false, nullptr);
6586
6587 // Report that we're falling back to the default value.
6588
7/14
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
2 LogErr(WARNING_LEVEL, ER_CANNOT_SET_LOG_ERROR_SERVICES,
6589 opt_log_error_services);
6590
6591
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (default_services != nullptr) opt_log_error_services = default_services;
6592 }
6593
6594 /*
6595 We'll want to flush whatever log-events we buffered during start-up
6596 to the now available components in a moment. To that end, we now
6597 switch from saving log-events in a buffer to processing them via
6598 the logging-pipeline.
6599 Not switching processors here would result in flushing the buffer
6600 into the buffer.
6601 */
6602 9757 log_line_process_hook_set(log_line_error_stack_run);
6603 9757 log_error_stage_set(LOG_ERROR_STAGE_COMPONENTS);
6604
6605 /*
6606 Set-up the error-log table, performance_schema.error_log.
6607 Try to populate it with previous runs' error-log and events
6608 buffered up to this point.
6609
6610 log_error_read_log_init() initializes the ring-buffer for
6611 performance_schema.error_log.
6612
6613 log_error_read_log() reads an existing error-log (of whatever formatting).
6614
6615 LOG_ERROR_STAGE_COMPONENTS_AND_PFS flags the error logging
6616 stack as fully operational, loadable components and all.
6617 In this mode, all submitted error-log events are also automatically
6618 added to performance_schema.error_log.
6619
6620 flush_error_log_messages() is called once any configured loadable
6621 error log-services are available. It flushes all buffered log-events
6622 to the log-services the user actually wants.
6623 If LOG_ERROR_STAGE_COMPONENTS_AND_PFS is set, also add the
6624 flushed events to performance_schema.error_log.
6625 */
6626
2/4
✓ Branch 0 taken 9757 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9757 times.
✗ Branch 3 not taken.
9757 assert((log_error_dest != nullptr) && (log_error_dest[0] != '\0'));
6627
6628
2/2
✓ Branch 0 taken 8638 times.
✓ Branch 1 taken 1119 times.
9757 if (!strcmp(log_error_dest, "stderr")) {
6629 // If we logging to stderr, there will be no log-file to read.
6630 // As this is a common case in mysql-test-run, we offer a fallback.
6631
6632 // Let the user know we cannot provide info from previous runs.
6633
7/14
✓ Branch 0 taken 8638 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8638 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8638 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8638 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 8638 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 8638 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 8638 times.
✗ Branch 13 not taken.
8638 LogErr(INFORMATION_LEVEL, ER_ERROR_LOG_DESTINATION_NOT_A_FILE, "stderr");
6634 // init logging to pfs
6635 8638 log_error_read_log_init();
6636 // flag log-stack as ready and enable logging to pfs
6637 8638 log_error_stage_set(LOG_ERROR_STAGE_COMPONENTS_AND_PFS);
6638 // flush messages, sending a copy to pfs
6639 8638 flush_error_log_messages();
6640 } else {
6641 // We're logging to a named file.
6642
6643 /*
6644 Flush messages, not sending a copy to pfs -- we'll get the info
6645 from the log-file anyway when we try to restore the previous run's
6646 info.
6647 */
6648 1119 flush_error_log_messages();
6649 /*
6650 Try to load error log events from the previous run (if available)
6651 and that from the current start-up into performance_schema.error_log.
6652 */
6653
1/2
✓ Branch 0 taken 1119 times.
✗ Branch 1 not taken.
1119 if (!log_error_read_log_init()) log_error_read_log(log_error_dest);
6654 // flag log-stack as ready and enable logging to pfs
6655 1119 log_error_stage_set(LOG_ERROR_STAGE_COMPONENTS_AND_PFS);
6656 }
6657
6658 9757 ret = 0; // Success!
6659
6660 9757 failure:
6661
6662 /*
6663 Destroy lock so plugin_register_early_plugins() > plugin_init_internals()
6664 can properly set up all plugin-related things together below.
6665 */
6666 9757 mysql_mutex_destroy(&LOCK_plugin);
6667
6668 9757 return ret;
6669 }
6670
6671 #if defined(MYSQL_ICU_DATADIR)
6672
6673 // For "bundled" ICU:
6674 // Verify that we can find <directory_path>/icudt69l
6675 // and <directory_path>/icudt69l/unames.icu
6676 // or <directory_path>/icudt69b on Sparc
6677 9472 static bool icu_data_directory_is_valid(const char *directory_path) {
6678 MY_STAT stat_info;
6679
1/2
✓ Branch 0 taken 9472 times.
✗ Branch 1 not taken.
9472 bool directory_exists = mysql_file_stat(key_file_misc, directory_path,
6680 9472 &stat_info, MYF(0)) != nullptr;
6681
1/2
✓ Branch 0 taken 9472 times.
✗ Branch 1 not taken.
9472 if (directory_exists) {
6682 char icudt_path[FN_REFLEN];
6683
1/2
✓ Branch 0 taken 9472 times.
✗ Branch 1 not taken.
9472 fn_format(icudt_path, ICUDT_DIR, directory_path, "", 0);
6684 bool icudt_dir_exists =
6685
1/2
✓ Branch 0 taken 9472 times.
✗ Branch 1 not taken.
9472 mysql_file_stat(key_file_misc, icudt_path, &stat_info, MYF(0));
6686
1/2
✓ Branch 0 taken 9472 times.
✗ Branch 1 not taken.
9472 if (icudt_dir_exists) {
6687 char icunames_path[FN_REFLEN];
6688
1/2
✓ Branch 0 taken 9472 times.
✗ Branch 1 not taken.
9472 fn_format(icunames_path, "unames.icu", icudt_path, "", 0);
6689 bool icu_unames_exists =
6690
1/2
✓ Branch 0 taken 9472 times.
✗ Branch 1 not taken.
9472 mysql_file_stat(key_file_misc, icunames_path, &stat_info, MYF(0));
6691
1/2
✓ Branch 0 taken 9472 times.
✗ Branch 1 not taken.
9472 if (icu_unames_exists) {
6692 9472 return true;
6693 }
6694 }
6695 }
6696 return false;
6697 }
6698
6699 // For "bundled" ICU:
6700 // Look for icudt69l.lnk in build directory.
6701 9472 static char *get_icu_data_directory_in_build_dir(char *to) {
6702 char icudt_path[FN_REFLEN];
6703
1/2
✓ Branch 0 taken 9472 times.
✗ Branch 1 not taken.
9472 fn_format(icudt_path, ICUDT_DIR, mysql_home, ".lnk", 0);
6704 MY_STAT stat_info;
6705 bool icudt_lnk_exists =
6706
1/2
✓ Branch 0 taken 9472 times.
✗ Branch 1 not taken.
9472 mysql_file_stat(key_file_misc, icudt_path, &stat_info, MYF(0)) != nullptr;
6707
2/2
✓ Branch 0 taken 9461 times.
✓ Branch 1 taken 11 times.
9472 if (icudt_lnk_exists) {
6708
1/2
✓ Branch 0 taken 9461 times.
✗ Branch 1 not taken.
9461 File file = mysql_file_open(key_file_misc, icudt_path, O_RDONLY, 0);
6709
1/2
✓ Branch 0 taken 9461 times.
✗ Branch 1 not taken.
9461 if (file != -1) {
6710 char icudt_lnk_contents[FN_REFLEN];
6711 size_t num_bytes_read =
6712
1/2
✓ Branch 0 taken 9461 times.
✗ Branch 1 not taken.
9461 mysql_file_read(file, reinterpret_cast<uchar *>(icudt_lnk_contents),
6713 sizeof(icudt_lnk_contents), 0);
6714
1/2
✓ Branch 0 taken 9461 times.
✗ Branch 1 not taken.
9461 mysql_file_close(file, 0);
6715
1/2
✓ Branch 0 taken 9461 times.
✗ Branch 1 not taken.
9461 if (num_bytes_read != MY_FILE_ERROR) {
6716 9461 icudt_lnk_contents[num_bytes_read] = '\0';
6717 9461 memcpy(to, icudt_lnk_contents, num_bytes_read + 1);
6718 9461 return to;
6719 }
6720 }
6721 }
6722 11 return nullptr;
6723 }
6724
6725 // For "bundled" ICU:
6726 // Look for MYSQL_ICU_DATADIR which depends on INSTALL_PRIV_LIBDIR
6727 11 static char *get_icu_data_directory_in_install_dir(char *to) {
6728 char buff[FN_REFLEN];
6729
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 const char *mysql_icu_datadir = get_relative_path(MYSQL_ICU_DATADIR);
6730
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 if (test_if_hard_path(mysql_icu_datadir))
6731
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 strmake(buff, mysql_icu_datadir, sizeof(buff) - 1);
6732 else
6733 strxnmov(buff, sizeof(buff) - 1, mysql_home, mysql_icu_datadir, NullS);
6734
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 convert_dirname(buff, buff, NullS);
6735 11 memcpy(to, buff, sizeof(buff));
6736 11 return to;
6737 }
6738
6739 // Where to look for data files for "bundled" ICU:
6740 // Look in environment ICU_DATA.
6741 // In a build sandbox we expect cmake to write a .lnk file.
6742 // In an install directory, we look in MYSQL_ICU_DATADIR.
6743 9472 static void init_icu_data_directory() {
6744 // Use environment variable if available.
6745 9472 const char *env_icu_data = getenv("ICU_DATA");
6746
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9472 times.
9472 if (env_icu_data != nullptr) {
6747 if (icu_data_directory_is_valid(env_icu_data)) {
6748 9472 return;
6749 }
6750 LogErr(WARNING_LEVEL, ER_REGEXP_MISSING_ICU_DATADIR, env_icu_data);
6751 // Continue, looking for ICU in build or install directory.
6752 }
6753
6754 char build_dir_buffer[FN_REFLEN];
6755
1/2
✓ Branch 0 taken 9472 times.
✗ Branch 1 not taken.
9472 const char *in_build = get_icu_data_directory_in_build_dir(build_dir_buffer);
6756
6/8
✓ Branch 0 taken 9461 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 9461 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9461 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 9461 times.
✓ Branch 7 taken 11 times.
9472 if (in_build != nullptr && icu_data_directory_is_valid(in_build)) {
6757
1/2
✓ Branch 0 taken 9461 times.
✗ Branch 1 not taken.
9461 u_setDataDirectory(in_build);
6758 9461 return;
6759 }
6760 char install_dir_buffer[FN_REFLEN];
6761 const char *in_install =
6762
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 get_icu_data_directory_in_install_dir(install_dir_buffer);
6763
4/8
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11 times.
✗ Branch 7 not taken.
11 if (in_install != nullptr && icu_data_directory_is_valid(in_install)) {
6764
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 u_setDataDirectory(in_install);
6765 11 return;
6766 }
6767 LogErr(WARNING_LEVEL, ER_REGEXP_MISSING_ICU_DATADIR, install_dir_buffer);
6768 }
6769
6770 #endif // MYSQL_ICU_DATADIR
6771
6772 9759 static int init_server_components() {
6773
1/2
✓ Branch 0 taken 9759 times.
✗ Branch 1 not taken.
9759 buffered_error_log.resize(buffered_error_log_size * 1024);
6774
6775
1/2
✓ Branch 0 taken 9759 times.
✗ Branch 1 not taken.
9759 DBUG_TRACE;
6776 /*
6777 We need to call each of these following functions to ensure that
6778 all things are initialized so that unireg_abort() doesn't fail
6779 */
6780
1/2
✓ Branch 0 taken 9759 times.
✗ Branch 1 not taken.
9759 mdl_init();
6781
1/2
✓ Branch 0 taken 9759 times.
✗ Branch 1 not taken.
9759 partitioning_init();
6782
5/10
✓ Branch 0 taken 9759 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9759 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9759 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 9759 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 9759 times.
9759 if (table_def_init() || hostname_cache_init(host_cache_size))
6783 unireg_abort(MYSQLD_ABORT_EXIT);
6784
6785 /*
6786 This load function has to be called after the opt_plugin_dir variable
6787 is initialized else it will fail to load.
6788 The unload of these components will be done by minimal_chassis_deinit().
6789 So, no need to call unload of these components.
6790 Since, it is an optional component required for GR, audit log etc. The
6791 error check of the service availability has to be done by those
6792 plugins/components.
6793 */
6794
6/6
✓ Branch 0 taken 9741 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 9531 times.
✓ Branch 3 taken 210 times.
✓ Branch 4 taken 9531 times.
✓ Branch 5 taken 228 times.
9759 if (!is_help_or_validate_option() && !opt_initialize)
6795
1/2
✓ Branch 0 taken 9531 times.
✗ Branch 1 not taken.
9531 dynamic_loader_srv->load(component_urns, NUMBER_OF_COMPONENTS);
6796
6797 /*
6798 Timers not needed if only starting with --help.
6799 */
6800
2/2
✓ Branch 0 taken 9741 times.
✓ Branch 1 taken 18 times.
9759 if (!is_help_or_validate_option()) {
6801
2/4
✓ Branch 0 taken 9741 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9741 times.
9741 if (my_timer_initialize())
6802 LogErr(ERROR_LEVEL, ER_CANT_INIT_TIMER, errno);
6803 else
6804 9741 have_statement_timeout = SHOW_OPTION_YES;
6805 }
6806
6807
1/2
✓ Branch 0 taken 9759 times.
✗ Branch 1 not taken.
9759 randominit(&sql_rand, (ulong)server_start_time, (ulong)server_start_time / 2);
6808 9759 setup_fpu();
6809
6810
1/2
✓ Branch 0 taken 9759 times.
✗ Branch 1 not taken.
9759 init_global_table_stats();
6811
1/2
✓ Branch 0 taken 9759 times.
✗ Branch 1 not taken.
9759 init_global_index_stats();
6812
6813
1/2
✓ Branch 0 taken 9757 times.
✗ Branch 1 not taken.
9759 setup_error_log(); // opens the log if needed
6814
6815 9757 enter_cond_hook = thd_enter_cond;
6816 9757 exit_cond_hook = thd_exit_cond;
6817 9757 enter_stage_hook = thd_enter_stage;
6818 9757 set_waiting_for_disk_space_hook = thd_set_waiting_for_disk_space;
6819 9757 is_killed_hook = thd_killed;
6820
6821
1/2
✓ Branch 0 taken 9757 times.
✗ Branch 1 not taken.
9757 xa::Transaction_cache::initialize();
6822
6823 /*
6824 Try to read the previous run's error log and make it available in
6825 performance_schema.error_log. Activate all error logging services
6826 requested by the user in @@global.log_error_services (now that the
6827 component infrastructure is available), flush the buffered error
6828 messages to performance schema and to configured services, and end
6829 error log buffering.
6830
6831 Pre-requisites:
6832 We depend on component_infrastructure_init() and setup_error_log()
6833 above. init_common_variables() additionally gives us a correctly
6834 set up umask etc., and keyring-migration may modify the log-target,
6835 so we wait that out as well. It should be safe to go before the
6836 component-autoload above ("component_urns") for the time being,
6837 but that may not be the case in the future, so we're playing it
6838 safe. Altogether by the time we get here, we're usually within
6839 a second of start-up, with a half-dozen or less messages buffered
6840 if no issues were encountered.
6841 */
6842
2/6
✓ Branch 0 taken 9757 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9757 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
9757 if (setup_error_log_components()) unireg_abort(MYSQLD_ABORT_EXIT);
6843
6844
2/4
✓ Branch 0 taken 9757 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9757 times.
9757 if (MDL_context_backup_manager::init()) {
6845 LogErr(ERROR_LEVEL, ER_OOM);
6846 unireg_abort(MYSQLD_ABORT_EXIT);
6847 }
6848
6849 /*
6850 initialize delegates for extension observers, errors have already
6851 been reported in the function
6852 */
6853
2/6
✓ Branch 0 taken 9757 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9757 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
9757 if (delegates_init()) unireg_abort(MYSQLD_ABORT_EXIT);
6854
6855 /* need to configure logging before initializing storage engines */
6856
4/4
✓ Branch 0 taken 9185 times.
✓ Branch 1 taken 572 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 9184 times.
9757 if (opt_log_replica_updates && !opt_bin_log) {
6857
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(WARNING_LEVEL, ER_NEED_LOG_BIN, "--log-replica-updates");
6858 }
6859 #ifdef WITH_WSREP
6860
7/8
✓ Branch 0 taken 9757 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9301 times.
✓ Branch 3 taken 456 times.
✓ Branch 4 taken 3305 times.
✓ Branch 5 taken 5996 times.
✓ Branch 6 taken 162 times.
✓ Branch 7 taken 3143 times.
9757 if (!WSREP_ON && binlog_format_used && !opt_bin_log)
6861 #else
6862 if (binlog_format_used && !opt_bin_log)
6863 #endif /* WITH_WSREP */
6864
8/16
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 162 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 162 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 162 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 162 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 162 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 162 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 162 times.
✗ Branch 15 not taken.
162 LogErr(WARNING_LEVEL, ER_NEED_LOG_BIN, "--binlog-format");
6865
6866 /* Check that we have not let the format to unspecified at this point */
6867
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9757 times.
9757 assert((uint)global_system_variables.binlog_format <=
6868 array_elements(binlog_format_names) - 1);
6869
6870 9757 opt_server_id_mask = ~ulong(0);
6871 9757 opt_server_id_mask =
6872
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9757 times.
9757 (opt_server_id_bits == 32) ? ~ulong(0) : (1 << opt_server_id_bits) - 1;
6873
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9757 times.
9757 if (server_id != (server_id & opt_server_id_mask)) {
6874 LogErr(ERROR_LEVEL, ER_SERVERID_TOO_LARGE);
6875 unireg_abort(MYSQLD_ABORT_EXIT);
6876 }
6877
6878
2/2
✓ Branch 0 taken 9225 times.
✓ Branch 1 taken 532 times.
9757 if (opt_bin_log) {
6879 /* Reports an error and aborts, if the --log-bin's path
6880 is a directory.*/
6881
2/2
✓ Branch 0 taken 4264 times.
✓ Branch 1 taken 4961 times.
9225 if (opt_bin_logname &&
6882
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4264 times.
4264 opt_bin_logname[strlen(opt_bin_logname) - 1] == FN_LIBCHAR) {
6883 LogErr(ERROR_LEVEL, ER_NEED_FILE_INSTEAD_OF_DIR, "--log-bin",
6884 opt_bin_logname);
6885 unireg_abort(MYSQLD_ABORT_EXIT);
6886 }
6887
6888 /* Reports an error and aborts, if the --log-bin-index's path
6889 is a directory.*/
6890
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 9222 times.
9225 if (opt_binlog_index_name &&
6891
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 opt_binlog_index_name[strlen(opt_binlog_index_name) - 1] ==
6892 FN_LIBCHAR) {
6893 LogErr(ERROR_LEVEL, ER_NEED_FILE_INSTEAD_OF_DIR, "--log-bin-index",
6894 opt_binlog_index_name);
6895 unireg_abort(MYSQLD_ABORT_EXIT);
6896 }
6897
6898 char buf[FN_REFLEN];
6899 const char *ln;
6900
2/2
✓ Branch 0 taken 4310 times.
✓ Branch 1 taken 4915 times.
9225 if (log_bin_supplied) {
6901 /*
6902 Binary log basename defaults to "`hostname`-bin" name prefix
6903 if --log-bin is used without argument.
6904 */
6905
1/2
✓ Branch 0 taken 4310 times.
✗ Branch 1 not taken.
4310 ln = mysql_bin_log.generate_name(opt_bin_logname, "-bin", buf);
6906 } else {
6907 /*
6908 Binary log basename defaults to "binlog" name prefix
6909 if --log-bin is not used.
6910 */
6911
1/2
✓ Branch 0 taken 4915 times.
✗ Branch 1 not taken.
4915 ln = mysql_bin_log.generate_name(opt_bin_logname, "", buf);
6912 }
6913
6914
5/6
✓ Branch 0 taken 4961 times.
✓ Branch 1 taken 4264 times.
✓ Branch 2 taken 4961 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 46 times.
✓ Branch 5 taken 4915 times.
9225 if (!opt_bin_logname && !opt_binlog_index_name && log_bin_supplied) {
6915 /*
6916 User didn't give us info to name the binlog index file.
6917 Picking `hostname`-bin.index like did in 4.x, causes replication to
6918 fail if the hostname is changed later. So, we would like to instead
6919 require a name. But as we don't want to break many existing setups, we
6920 only give warning, not error.
6921 */
6922
8/16
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 46 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 46 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 46 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 46 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 46 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 46 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 46 times.
✗ Branch 15 not taken.
46 LogErr(INFORMATION_LEVEL, ER_LOG_BIN_BETTER_WITH_NAME, ln);
6923 }
6924
1/2
✓ Branch 0 taken 9225 times.
✗ Branch 1 not taken.
9225 if (ln == buf) {
6925
1/2
✓ Branch 0 taken 9225 times.
✗ Branch 1 not taken.
9225 my_free(opt_bin_logname);
6926
1/2
✓ Branch 0 taken 9225 times.
✗ Branch 1 not taken.
9225 opt_bin_logname = my_strdup(key_memory_opt_bin_logname, buf, MYF(0));
6927 }
6928
6929 #ifdef WITH_WSREP
6930 } /* closing opt_binlog */
6931 #endif /* WITH_WSREP */
6932
6933 #ifdef WITH_WSREP /* WSREP BEFORE SE */
6934 /*
6935 Wsrep initialization must happen at this point, because:
6936 - opt_bin_logname must be known when starting replication
6937 since SST may need it
6938 - SST may modify binlog index file, so it must be opened
6939 after SST has happened
6940 */
6941
2/4
✓ Branch 0 taken 9757 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9757 times.
9757 if (gtid_server_init()) {
6942 LogErr(ERROR_LEVEL, ER_CANT_INITIALIZE_GTID);
6943 unireg_abort(MYSQLD_ABORT_EXIT);
6944 }
6945
6946 /* Init server even for recover as it is needed for initialization
6947 of THD structure. */
6948
2/6
✓ Branch 0 taken 9757 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9757 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
9757 if (wsrep_init_server()) unireg_abort(MYSQLD_ABORT_EXIT);
6949
6950
2/2
✓ Branch 0 taken 9741 times.
✓ Branch 1 taken 16 times.
9757 if (!wsrep_recovery) {
6951
6/6
✓ Branch 0 taken 402 times.
✓ Branch 1 taken 9339 times.
✓ Branch 2 taken 196 times.
✓ Branch 3 taken 206 times.
✓ Branch 4 taken 179 times.
✓ Branch 5 taken 9562 times.
9937 if (pxc_encrypt_cluster_traffic && !opt_initialize &&
6952
2/2
✓ Branch 0 taken 179 times.
✓ Branch 1 taken 17 times.
196 !is_help_or_validate_option()) {
6953
1/2
✓ Branch 0 taken 179 times.
✗ Branch 1 not taken.
358 bool bootstrap = (wsrep_new_cluster ||
6954
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 175 times.
179 (strcmp(wsrep_cluster_address, "gcomm://") == 0));
6955
3/6
✓ Branch 0 taken 179 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 179 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 179 times.
179 if (TLS_channel::singleton_init(&mysql_main, mysql_main_channel,
6956 opt_use_ssl, &server_main_callback,
6957 opt_initialize)) {
6958 unireg_abort(MYSQLD_ABORT_EXIT);
6959 }
6960
2/4
✓ Branch 0 taken 179 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 179 times.
179 if (server_main_callback.wsrep_ssl_artifacts_check(bootstrap)) {
6961 unireg_abort(MYSQLD_ABORT_EXIT);
6962 }
6963 }
6964 #if 0
6965 ssl_artifacts_status auto_detection_status = auto_detect_ssl();
6966 if (auto_detection_status == SSL_ARTIFACTS_AUTO_DETECTED)
6967 sql_print_information(
6968 "Found %s, %s and %s in data directory. "
6969 "Trying to enable SSL support using them.",
6970 DEFAULT_SSL_CA_CERT, DEFAULT_SSL_SERVER_CERT,
6971 DEFAULT_SSL_SERVER_KEY);
6972
6973 /* Generate certs automatically only when bootstrapping
6974 to avoid cases where starting up creates incompatible certs */
6975 if (wsrep_new_cluster) {
6976 if (do_auto_cert_generation(auto_detection_status) == false)
6977 unireg_abort(MYSQLD_ABORT_EXIT);
6978 } else {
6979 WSREP_INFO(
6980 "Skipping automatic SSL certificate generation"
6981 " (enabled only in bootstrap mode)");
6982 }
6983 #endif /* 0 */
6984
6985 /* Disable wsrep functionality with bootstrap */
6986
2/2
✓ Branch 0 taken 211 times.
✓ Branch 1 taken 9530 times.
9741 if (opt_initialize) {
6987
1/2
✓ Branch 0 taken 211 times.
✗ Branch 1 not taken.
211 wsrep_provider_init(WSREP_NONE);
6988
2/6
✓ Branch 0 taken 211 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 211 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
211 if (wsrep_init()) unireg_abort(MYSQLD_ABORT_EXIT);
6989 } else {
6990 /* add basedir/bin to PATH to resolve wsrep script names */
6991 9530 int mysql_home_len = strlen(mysql_home);
6992 9530 char *const tmp_path((char *)alloca(mysql_home_len + strlen("/bin") + 1));
6993
1/2
✓ Branch 0 taken 9530 times.
✗ Branch 1 not taken.
9530 if (tmp_path) {
6994 9530 strcpy(tmp_path, mysql_home);
6995 /* mysql_home may already contain a trailing slash: */
6996
1/2
✓ Branch 0 taken 9530 times.
✗ Branch 1 not taken.
19060 strcat(tmp_path,
6997
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9530 times.
9530 (mysql_home_len == 0 || mysql_home[mysql_home_len - 1] != '/')
6998 ? "/bin"
6999 : "bin");
7000
1/2
✓ Branch 0 taken 9530 times.
✗ Branch 1 not taken.
9530 wsrep_prepend_PATH(tmp_path);
7001 } else {
7002 WSREP_ERROR("Could not append %s/bin to PATH", mysql_home);
7003 }
7004
7005
3/4
✓ Branch 0 taken 9530 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 440 times.
✓ Branch 3 taken 9090 times.
9530 if (wsrep_before_SE()) {
7006
1/2
✓ Branch 0 taken 440 times.
✗ Branch 1 not taken.
440 set_ports(); // this is also called in network_init() later but we need
7007 // to know mysqld_port now - lp:1071882
7008
1/2
✓ Branch 0 taken 437 times.
✗ Branch 1 not taken.
440 wsrep_init_startup(true);
7009 }
7010 }
7011 }
7012
7013 /*
7014 * Forcing a new setwd in case the SST mounted the datadir
7015 */
7016
3/4
✓ Branch 0 taken 9736 times.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9754 times.
19490 if (!is_help_or_validate_option() &&
7017
2/4
✓ Branch 0 taken 9736 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9736 times.
9736 my_setwd(mysql_real_data_home, MYF(MY_WME)))
7018 unireg_abort(MYSQLD_ABORT_EXIT);
7019
7020
2/2
✓ Branch 0 taken 9222 times.
✓ Branch 1 taken 532 times.
9754 if (opt_bin_log) {
7021 /*
7022 Variable ln is not defined at this scope. We use opt_bin_logname instead.
7023 It should be the same as ln since
7024 - mysql_bin_log.generate_name() returns first argument if new log name
7025 is not generated
7026 - if new log name is generated, return value is assigned to ln and copied
7027 to opt_bin_logname above
7028 */
7029
3/4
✓ Branch 0 taken 9206 times.
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9222 times.
18428 if (!is_help_or_validate_option() &&
7030
2/4
✓ Branch 0 taken 9206 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9206 times.
9206 mysql_bin_log.open_index_file(opt_binlog_index_name, opt_bin_logname,
7031 true)) {
7032 unireg_abort(MYSQLD_ABORT_EXIT);
7033 }
7034 }
7035 #else
7036 /*
7037 Skip opening the index file if we start with --help. This is necessary
7038 to avoid creating the file in an otherwise empty datadir, which will
7039 cause a succeeding 'mysqld --initialize' to fail.
7040 */
7041 if (!is_help_or_validate_option() &&
7042 mysql_bin_log.open_index_file(opt_binlog_index_name, ln, true)) {
7043 unireg_abort(MYSQLD_ABORT_EXIT);
7044 }
7045 }
7046 #endif /* WITH_WSREP */
7047
7048
2/2
✓ Branch 0 taken 9222 times.
✓ Branch 1 taken 532 times.
9754 if (opt_bin_log) {
7049 /*
7050 opt_bin_logname[0] needs to be checked to make sure opt binlog name is
7051 not an empty string, in case it is an empty string default file
7052 extension will be passed
7053 */
7054
2/2
✓ Branch 0 taken 4309 times.
✓ Branch 1 taken 4913 times.
9222 if (log_bin_supplied) {
7055
1/2
✓ Branch 0 taken 4309 times.
✗ Branch 1 not taken.
4309 log_bin_basename = rpl_make_log_name(
7056 key_memory_MYSQL_BIN_LOG_basename, opt_bin_logname,
7057 default_logfile_name,
7058
2/4
✓ Branch 0 taken 4309 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4309 times.
✗ Branch 3 not taken.
4309 (opt_bin_logname && opt_bin_logname[0]) ? "" : "-bin");
7059 } else {
7060 4913 log_bin_basename =
7061
1/2
✓ Branch 0 taken 4913 times.
✗ Branch 1 not taken.
4913 rpl_make_log_name(key_memory_MYSQL_BIN_LOG_basename, opt_bin_logname,
7062 default_binlogfile_name, "");
7063 }
7064
7065 9222 log_bin_index =
7066
1/2
✓ Branch 0 taken 9222 times.
✗ Branch 1 not taken.
9222 rpl_make_log_name(key_memory_MYSQL_BIN_LOG_index, opt_binlog_index_name,
7067 log_bin_basename, ".index");
7068
7069
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 9219 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
9222 if ((!opt_binlog_index_name || !opt_binlog_index_name[0]) &&
7070
1/2
✓ Branch 0 taken 9219 times.
✗ Branch 1 not taken.
9219 log_bin_index) {
7071 18438 strmake(default_binlog_index_name,
7072
2/4
✓ Branch 0 taken 9219 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9219 times.
✗ Branch 3 not taken.
9219 log_bin_index + dirname_length(log_bin_index),
7073 FN_REFLEN + index_ext_length - 1);
7074 9219 opt_binlog_index_name = default_binlog_index_name;
7075 }
7076
7077
2/4
✓ Branch 0 taken 9222 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9222 times.
9222 if (log_bin_basename == nullptr || log_bin_index == nullptr) {
7078 LogErr(ERROR_LEVEL, ER_RPL_CANT_MAKE_PATHS, (int)FN_REFLEN, (int)FN_LEN);
7079 unireg_abort(MYSQLD_ABORT_EXIT);
7080 }
7081 }
7082
7083
3/8
✓ Branch 0 taken 9754 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9754 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9754 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
9754 DBUG_PRINT("debug",
7084 ("opt_bin_logname: %s, opt_relay_logname: %s, pidfile_name: %s",
7085 opt_bin_logname, opt_relay_logname, pidfile_name));
7086
7087 /*
7088 opt_relay_logname[0] needs to be checked to make sure opt relaylog name is
7089 not an empty string, in case it is an empty string default file
7090 extension will be passed
7091 */
7092
1/2
✓ Branch 0 taken 9754 times.
✗ Branch 1 not taken.
9754 relay_log_basename = rpl_make_log_name(
7093 key_memory_MYSQL_RELAY_LOG_basename, opt_relay_logname,
7094 default_logfile_name,
7095
3/4
✓ Branch 0 taken 3020 times.
✓ Branch 1 taken 6734 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3020 times.
9754 (opt_relay_logname && opt_relay_logname[0]) ? "" : relay_ext);
7096
7097
3/4
✓ Branch 0 taken 3020 times.
✓ Branch 1 taken 6734 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3020 times.
9754 if (!opt_relay_logname || !opt_relay_logname[0]) {
7098
1/2
✓ Branch 0 taken 6734 times.
✗ Branch 1 not taken.
6734 if (relay_log_basename) {
7099 13468 strmake(default_relaylogfile_name,
7100
2/4
✓ Branch 0 taken 6734 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6734 times.
✗ Branch 3 not taken.
6734 relay_log_basename + dirname_length(relay_log_basename),
7101 FN_REFLEN + relay_ext_length - 1);
7102 6734 opt_relay_logname = default_relaylogfile_name;
7103 }
7104 } else
7105 3020 opt_relay_logname_supplied = true;
7106
7107
1/2
✓ Branch 0 taken 9754 times.
✗ Branch 1 not taken.
9754 if (relay_log_basename != nullptr)
7108
1/2
✓ Branch 0 taken 9754 times.
✗ Branch 1 not taken.
9754 relay_log_index = rpl_make_log_name(key_memory_MYSQL_RELAY_LOG_index,
7109 opt_relaylog_index_name,
7110 relay_log_basename, ".index");
7111
7112
3/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 9746 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
9754 if (!opt_relaylog_index_name || !opt_relaylog_index_name[0]) {
7113
1/2
✓ Branch 0 taken 9746 times.
✗ Branch 1 not taken.
9746 if (relay_log_index) {
7114 19492 strmake(default_relaylog_index_name,
7115
2/4
✓ Branch 0 taken 9746 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9746 times.
✗ Branch 3 not taken.
9746 relay_log_index + dirname_length(relay_log_index),
7116 FN_REFLEN + relay_ext_length + index_ext_length - 1);
7117 9746 opt_relaylog_index_name = default_relaylog_index_name;
7118 }
7119 } else
7120 8 opt_relaylog_index_name_supplied = true;
7121
7122
2/4
✓ Branch 0 taken 9754 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9754 times.
9754 if (relay_log_basename == nullptr || relay_log_index == nullptr) {
7123 LogErr(ERROR_LEVEL, ER_RPL_CANT_MAKE_PATHS, (int)FN_REFLEN, (int)FN_LEN);
7124 unireg_abort(MYSQLD_ABORT_EXIT);
7125 }
7126
7127
2/2
✓ Branch 0 taken 9222 times.
✓ Branch 1 taken 532 times.
9754 if (log_bin_basename != nullptr &&
7128
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9220 times.
9222 !strcmp(log_bin_basename, relay_log_basename)) {
7129 2 const int bin_ext_length = 4;
7130 char default_binlogfile_name_from_hostname[FN_REFLEN + bin_ext_length];
7131 /* Generate default bin log file name. */
7132
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 strmake(default_binlogfile_name_from_hostname, default_logfile_name,
7133 FN_REFLEN - 1);
7134 2 strcat(default_binlogfile_name_from_hostname, "-bin");
7135
7136
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (!default_relaylogfile_name[0]) {
7137 /* Generate default relay log file name. */
7138
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 strmake(default_relaylogfile_name, default_logfile_name, FN_REFLEN - 1);
7139 2 strcat(default_relaylogfile_name, relay_ext);
7140 }
7141 /*
7142 Reports an error and aborts, if the same base name is specified
7143 for both binary and relay logs.
7144 */
7145
8/16
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 2 times.
✗ Branch 15 not taken.
2 LogErr(ERROR_LEVEL, ER_RPL_CANT_HAVE_SAME_BASENAME, log_bin_basename,
7146 "--log-bin", default_binlogfile_name,
7147 default_binlogfile_name_from_hostname, "--relay-log",
7148 default_relaylogfile_name);
7149
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
2 unireg_abort(MYSQLD_ABORT_EXIT);
7150 }
7151
7152
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 9746 times.
9752 if (global_system_variables.binlog_row_value_options != 0) {
7153 6 const char *msg = nullptr;
7154 6 longlong err = ER_BINLOG_ROW_VALUE_OPTION_IGNORED;
7155
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5 times.
6 if (!opt_bin_log)
7156 1 msg = "the binary log is disabled";
7157
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 4 times.
5 else if (global_system_variables.binlog_format == BINLOG_FORMAT_STMT)
7158 1 msg = "binlog_format=STATEMENT";
7159
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
4 else if (log_bin_use_v1_row_events) {
7160 1 msg = "binlog_row_value_options=PARTIAL_JSON";
7161 1 err = ER_BINLOG_USE_V1_ROW_EVENTS_IGNORED;
7162
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 } else if (global_system_variables.binlog_row_image ==
7163 BINLOG_ROW_IMAGE_FULL) {
7164 1 msg = "binlog_row_image=FULL";
7165 1 err = ER_BINLOG_ROW_VALUE_OPTION_USED_ONLY_FOR_AFTER_IMAGES;
7166 }
7167
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
6 if (msg) {
7168
2/3
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
4 switch (err) {
7169 3 case ER_BINLOG_ROW_VALUE_OPTION_IGNORED:
7170 case ER_BINLOG_ROW_VALUE_OPTION_USED_ONLY_FOR_AFTER_IMAGES:
7171
8/16
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
3 LogErr(WARNING_LEVEL, err, msg, "PARTIAL_JSON");
7172 3 break;
7173 1 case ER_BINLOG_USE_V1_ROW_EVENTS_IGNORED:
7174
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(WARNING_LEVEL, err, msg);
7175 1 break;
7176 default:
7177 assert(0); /* purecov: deadcode */
7178 }
7179 }
7180 }
7181
7182 /* call ha_init_key_cache() on all key caches to init them */
7183
1/2
✓ Branch 0 taken 9752 times.
✗ Branch 1 not taken.
9752 process_key_caches(&ha_init_key_cache);
7184
7185 /* Allow storage engine to give real error messages */
7186
2/4
✓ Branch 0 taken 9752 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9752 times.
9752 if (ha_init_errors()) return 1;
7187
7188 #ifndef WITH_WSREP
7189 /* Leave the original location if wsrep is not involved otherwise
7190 we do this before initializing WSREP as wsrep needs access to
7191 gtid_mode which and for accessing gtid_mode gtid_sid_locks has to be
7192 initialized which is done by this function. */
7193
7194 if (gtid_server_init()) {
7195 LogErr(ERROR_LEVEL, ER_CANT_INITIALIZE_GTID);
7196 unireg_abort(MYSQLD_ABORT_EXIT);
7197 }
7198 #endif /* !WITH_WSREP */
7199
7200
4/4
✓ Branch 0 taken 9180 times.
✓ Branch 1 taken 572 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 9178 times.
9752 if (opt_log_replica_updates && replicate_same_server_id) {
7201
4/8
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
2 if (opt_bin_log && global_gtid_mode.get() != Gtid_mode::ON) {
7202 LogErr(ERROR_LEVEL, ER_RPL_INFINITY_DENIED);
7203 unireg_abort(MYSQLD_ABORT_EXIT);
7204 } else
7205
8/16
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 2 times.
✗ Branch 15 not taken.
2 LogErr(WARNING_LEVEL, ER_RPL_INFINITY_IGNORED);
7206 }
7207
7208 {
7209 /*
7210 We have to call a function in log_resource.cc, or its references
7211 won't be visible to plugins.
7212 */
7213 #ifndef NDEBUG
7214 int dummy =
7215 #endif
7216
1/2
✓ Branch 0 taken 9752 times.
✗ Branch 1 not taken.
9752 Log_resource::dummy_function_to_ensure_we_are_linked_into_the_server();
7217
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9752 times.
9752 assert(dummy == 1);
7218 }
7219
7220 /*
7221 We need to initialize the UDF globals early before reading the proc table
7222 and before the server component initialization to allow other components
7223 to register their UDFs at init time and de-register them at deinit time.
7224 */
7225
1/2
✓ Branch 0 taken 9752 times.
✗ Branch 1 not taken.
9752 udf_init_globals();
7226
7227 /*
7228 Set tc_log to point to TC_LOG_DUMMY early in order to allow plugin_init()
7229 to commit attachable transaction after reading from mysql.plugin table.
7230 If necessary tc_log will be adjusted to point to correct TC_LOG instance
7231 later.
7232 */
7233 9752 tc_log = &tc_log_dummy;
7234
7235 /*
7236 Each server should have one UUID. We will create it automatically, if it
7237 does not exist. It should be initialized before opening binlog file. Because
7238 server's uuid will be stored into the new binlog file.
7239 */
7240
5/8
✓ Branch 0 taken 9734 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 9734 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9734 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 9752 times.
9752 if (!is_help_or_validate_option() && init_server_auto_options()) {
7241 LogErr(ERROR_LEVEL, ER_CANT_CREATE_UUID);
7242 unireg_abort(MYSQLD_ABORT_EXIT);
7243 }
7244
7245 /*Load early plugins */
7246
4/6
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9734 times.
✓ Branch 2 taken 9752 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9752 times.
9752 if (plugin_register_early_plugins(&remaining_argc, remaining_argv,
7247 9752 (is_help_or_validate_option())
7248 ? PLUGIN_INIT_SKIP_INITIALIZATION
7249 : 0)) {
7250 LogErr(ERROR_LEVEL, ER_CANT_INITIALIZE_EARLY_PLUGINS);
7251 unireg_abort(1);
7252 }
7253
7254 /* Load builtin plugins, initialize MyISAM, CSV and InnoDB */
7255
3/4
✓ Branch 0 taken 9752 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 9735 times.
9752 if (plugin_register_builtin_and_init_core_se(&remaining_argc,
7256 remaining_argv)) {
7257
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if (!opt_validate_config)
7258
8/16
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 17 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 17 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 17 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 17 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 17 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 17 times.
✗ Branch 15 not taken.
17 LogErr(ERROR_LEVEL, ER_CANT_INITIALIZE_BUILTIN_PLUGINS);
7259
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
17 unireg_abort(1);
7260 }
7261
7262 /*
7263 Needs to be done before dd::init() which runs DDL commands (for real)
7264 during instance initialization.
7265 */
7266
1/2
✓ Branch 0 taken 9735 times.
✗ Branch 1 not taken.
9735 init_sql_command_flags();
7267
7268 /*
7269 plugin_register_dynamic_and_init_all() needs DD initialized.
7270 Initialize DD to create data directory using current server.
7271 */
7272
2/2
✓ Branch 0 taken 207 times.
✓ Branch 1 taken 9528 times.
9735 if (opt_initialize) {
7273
2/2
✓ Branch 0 taken 206 times.
✓ Branch 1 taken 1 times.
207 if (!is_help_or_validate_option()) {
7274
3/4
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 202 times.
206 if (dd::init(dd::enum_dd_init_type::DD_INITIALIZE)) {
7275
8/16
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 4 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 4 times.
✗ Branch 15 not taken.
4 LogErr(ERROR_LEVEL, ER_DD_INIT_FAILED);
7276
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
4 unireg_abort(1);
7277 }
7278
7279
2/4
✓ Branch 0 taken 202 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 202 times.
202 if (dd::init(dd::enum_dd_init_type::DD_INITIALIZE_SYSTEM_VIEWS)) {
7280 LogErr(ERROR_LEVEL, ER_SYSTEM_VIEW_INIT_FAILED);
7281 unireg_abort(1);
7282 }
7283 }
7284 } else {
7285 /*
7286 Initialize DD in case of upgrade and normal normal server restart.
7287 It is detected if we are starting on old data directory or current
7288 data directory. If it is old data directory, DD tables are created.
7289 If server is starting on data directory with DD tables, DD is initialized.
7290 */
7291
4/4
✓ Branch 0 taken 9511 times.
✓ Branch 1 taken 17 times.
✓ Branch 2 taken 105 times.
✓ Branch 3 taken 9421 times.
19037 if (!is_help_or_validate_option() &&
7292
3/4
✓ Branch 0 taken 9509 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 105 times.
✓ Branch 3 taken 9404 times.
9511 dd::init(dd::enum_dd_init_type::DD_RESTART_OR_UPGRADE)) {
7293
8/16
✓ Branch 0 taken 105 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 105 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 105 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 105 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 105 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 105 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 105 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 105 times.
✗ Branch 15 not taken.
105 LogErr(ERROR_LEVEL, ER_DD_INIT_FAILED);
7294
7295
3/4
✓ Branch 0 taken 105 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 102 times.
✓ Branch 3 taken 3 times.
105 if (!dd::upgrade::no_server_upgrade_required()) {
7296 102 dd_init_failed_during_upgrade = true;
7297 }
7298
7299 /* If clone recovery fails, we rollback the files to previous
7300 dataset and attempt to restart server. */
7301 105 int exit_code =
7302
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 105 times.
105 clone_recovery_error ? MYSQLD_RESTART_EXIT : MYSQLD_ABORT_EXIT;
7303
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
105 unireg_abort(exit_code);
7304 }
7305 }
7306
7307 /*
7308 During plugin initialization, a plugin may expect (depending on what the
7309 plugin actually does) to find a functional server, including:
7310 - mysql system tables
7311 - information schema tables
7312 - performance schema tables
7313 - data dictionary
7314 - components / services, including the registry service
7315 During the server installation, all these parts are not available yet, as
7316 they are created during the installation process with mysqld --initialize.
7317
7318 As a result, plugins are not loaded during mysqld --initialize, so that
7319 the server install can proceed and complete before any plugin is loaded
7320 through any config file or pre-programmed command line.
7321 */
7322 9624 int flags = 0;
7323
7324
2/2
✓ Branch 0 taken 219 times.
✓ Branch 1 taken 9405 times.
9624 if (opt_noacl) flags |= PLUGIN_INIT_SKIP_PLUGIN_TABLE;
7325
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9606 times.
9624 if (is_help_or_validate_option())
7326 18 flags |= PLUGIN_INIT_SKIP_INITIALIZATION | PLUGIN_INIT_SKIP_PLUGIN_TABLE;
7327
2/2
✓ Branch 0 taken 203 times.
✓ Branch 1 taken 9421 times.
9624 if (opt_initialize) flags |= PLUGIN_INIT_SKIP_DYNAMIC_LOADING;
7328
7329 /*
7330 In the case of upgrade, we need to delay initialization of plugins that
7331 depend on e.g. mysql tables that will be changed during upgrade.
7332 */
7333
2/2
✓ Branch 0 taken 9404 times.
✓ Branch 1 taken 202 times.
19230 if (!is_help_or_validate_option() && !opt_initialize &&
7334
7/8
✓ Branch 0 taken 9606 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 9404 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 205 times.
✓ Branch 5 taken 9199 times.
✓ Branch 6 taken 202 times.
✓ Branch 7 taken 9422 times.
19435 !dd::upgrade::no_server_upgrade_required() &&
7335
2/2
✓ Branch 0 taken 202 times.
✓ Branch 1 taken 3 times.
205 opt_upgrade_mode != UPGRADE_MINIMAL)
7336 202 flags |= PLUGIN_INIT_DELAY_UNTIL_AFTER_UPGRADE;
7337
7338 /*
7339 Initialize the cost model, but delete it after the plugins are initialized.
7340 Cost model is needed while dropping and creating pfs tables to
7341 update metadata of referencing views (if there are any).
7342 */
7343
1/2
✓ Branch 0 taken 9624 times.
✗ Branch 1 not taken.
9624 init_optimizer_cost_module(true);
7344 { // New scope in which the error handler hook is modified.
7345 9624 ErrorHandlerFunctionPointer ehh_val = error_handler_hook;
7346 19248 auto restore_ehh = create_scope_guard([ehh_val]() {
7347
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9624 times.
9624 assert(ehh_val == my_message_stderr);
7348 9624 error_handler_hook = ehh_val;
7349
1/2
✓ Branch 0 taken 9624 times.
✗ Branch 1 not taken.
9624 });
7350 9624 error_handler_hook = +[](uint c, const char *s, myf f) {
7351
4/4
✓ Branch 0 taken 2256 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 2248 times.
2258 if (c != ER_NO_SUCH_TABLE || strstr(s, "mysql.server_cost") == nullptr) {
7352 10 my_message_stderr(c, s, f);
7353 }
7354 2258 };
7355
2/4
✓ Branch 0 taken 9624 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9624 times.
9624 if (plugin_register_dynamic_and_init_all(&remaining_argc, remaining_argv,
7356 flags)) {
7357 delete_optimizer_cost_module();
7358 // Delete all DD tables in case of error in initializing plugins.
7359 if (dd::upgrade_57::in_progress())
7360 (void)dd::init(dd::enum_dd_init_type::DD_DELETE);
7361
7362 if (!opt_validate_config)
7363 LogErr(ERROR_LEVEL, ER_CANT_INITIALIZE_DYNAMIC_PLUGINS);
7364 unireg_abort(MYSQLD_ABORT_EXIT);
7365 }
7366 9624 } // End of extra scope where missing server_cost errors are not logged
7367
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9624 times.
9624 assert(error_handler_hook == my_message_stderr);
7368 9624 dynamic_plugins_are_initialized =
7369 true; /* Don't separate from init function */
7370
1/2
✓ Branch 0 taken 9624 times.
✗ Branch 1 not taken.
9624 delete_optimizer_cost_module();
7371
7372 9624 LEX_CSTRING plugin_name = {STRING_WITH_LEN("thread_pool")};
7373 19248 if (Connection_handler_manager::thread_handling !=
7374
4/4
✓ Branch 0 taken 9608 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 9608 times.
19232 Connection_handler_manager::SCHEDULER_ONE_THREAD_PER_CONNECTION ||
7375
2/4
✓ Branch 0 taken 9608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9608 times.
9608 plugin_is_ready(plugin_name, MYSQL_DAEMON_PLUGIN)) {
7376
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 auto res_grp_mgr = resourcegroups::Resource_group_mgr::instance();
7377
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 res_grp_mgr->disable_resource_group();
7378
2/4
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
16 res_grp_mgr->set_unsupport_reason("Thread pool plugin enabled");
7379 }
7380
7381 #ifdef WITH_WSREP
7382 static const LEX_CSTRING keyring_vault_name = {
7383 STRING_WITH_LEN("keyring_vault")};
7384 static const LEX_CSTRING keyring_name = {STRING_WITH_LEN("keyring_file")};
7385
4/4
✓ Branch 0 taken 9275 times.
✓ Branch 1 taken 349 times.
✓ Branch 2 taken 506 times.
✓ Branch 3 taken 9118 times.
18899 if (!pxc_encrypt_cluster_traffic &&
7386
2/4
✓ Branch 0 taken 9275 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9275 times.
✗ Branch 3 not taken.
9275 (plugin_is_ready(keyring_vault_name, MYSQL_KEYRING_PLUGIN) ||
7387
3/4
✓ Branch 0 taken 9275 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 506 times.
✓ Branch 3 taken 8769 times.
9275 plugin_is_ready(keyring_name, MYSQL_KEYRING_PLUGIN))) {
7388
10/22
✓ Branch 0 taken 506 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 506 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 506 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 506 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 506 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 506 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 506 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 506 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 506 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 506 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
506 WSREP_WARN(
7389 "You have enabled keyring plugin. SST encryption is mandatory. "
7390 "Please enable pxc_encrypt_cluster_traffic. Check "
7391 "https://www.percona.com/doc/percona-xtradb-cluster/%u.%u/security/"
7392 "encrypt-traffic.html#encrypt-sst for more details.",
7393 MYSQL_VERSION_MAJOR, MYSQL_VERSION_MINOR);
7394 }
7395 #endif
7396
7397 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
7398 /*
7399 A value of the variable dd_upgrade_flag is reset after
7400 dd::init(dd::enum_dd_init_type::DD_POPULATE_UPGRADE) returned.
7401 So make its copy to call init_pfs_tables() with right argument value later.
7402 */
7403
1/2
✓ Branch 0 taken 9624 times.
✗ Branch 1 not taken.
9624 bool dd_upgrade_was_initiated = dd::upgrade_57::in_progress();
7404 #endif
7405
7406
7/8
✓ Branch 0 taken 9606 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 9606 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 79 times.
✓ Branch 5 taken 9527 times.
✓ Branch 6 taken 79 times.
✓ Branch 7 taken 9545 times.
9624 if (!is_help_or_validate_option() && dd::upgrade_57::in_progress()) {
7407 // Populate DD tables with meta data from 5.7
7408
3/4
✓ Branch 0 taken 79 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 59 times.
79 if (dd::init(dd::enum_dd_init_type::DD_POPULATE_UPGRADE)) {
7409
8/16
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 20 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 20 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 20 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 20 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 20 times.
✗ Branch 15 not taken.
20 LogErr(ERROR_LEVEL, ER_DD_POPULATING_TABLES_FAILED);
7410
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
20 unireg_abort(1);
7411 }
7412 // Run after_dd_upgrade hook
7413
3/8
✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 59 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 59 times.
59 if (RUN_HOOK(server_state, after_dd_upgrade_from_57, (nullptr)))
7414 unireg_abort(MYSQLD_ABORT_EXIT);
7415 }
7416
7417 /*
7418 Store server and plugin IS tables metadata into new DD.
7419 This is done after all the plugins are registered.
7420 */
7421
2/2
✓ Branch 0 taken 9384 times.
✓ Branch 1 taken 202 times.
19190 if (!is_help_or_validate_option() && !opt_initialize &&
7422
5/8
✓ Branch 0 taken 9586 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 9384 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9384 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 9604 times.
28574 !dd::upgrade_57::in_progress() &&
7423
2/4
✓ Branch 0 taken 9384 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9384 times.
9384 dd::init(dd::enum_dd_init_type::DD_UPDATE_I_S_METADATA)) {
7424 LogErr(ERROR_LEVEL, ER_DD_UPDATING_PLUGIN_MD_FAILED);
7425 unireg_abort(MYSQLD_ABORT_EXIT);
7426 }
7427
7428 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
7429
2/2
✓ Branch 0 taken 9586 times.
✓ Branch 1 taken 18 times.
9604 if (!is_help_or_validate_option()) {
7430 /*
7431 Initialize the cost model, but delete it after the pfs is initialized.
7432 Cost model is needed while dropping and creating pfs tables to
7433 update metadata of referencing views (if there are any).
7434 */
7435
1/2
✓ Branch 0 taken 9586 times.
✗ Branch 1 not taken.
9586 init_optimizer_cost_module(true);
7436
7437 bool st;
7438
4/4
✓ Branch 0 taken 9384 times.
✓ Branch 1 taken 202 times.
✓ Branch 2 taken 9325 times.
✓ Branch 3 taken 59 times.
9586 if (opt_initialize || dd_upgrade_was_initiated ||
7439
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 9259 times.
9325 opt_upgrade_mode == UPGRADE_FORCE)
7440
1/2
✓ Branch 0 taken 327 times.
✗ Branch 1 not taken.
327 st = dd::performance_schema::init_pfs_tables(
7441 dd::enum_dd_init_type::DD_INITIALIZE);
7442 else
7443
1/2
✓ Branch 0 taken 9259 times.
✗ Branch 1 not taken.
9259 st = dd::performance_schema::init_pfs_tables(
7444 dd::enum_dd_init_type::DD_RESTART_OR_UPGRADE);
7445
7446 /* Now that the pfs is initialized, delete the cost model. */
7447
1/2
✓ Branch 0 taken 9586 times.
✗ Branch 1 not taken.
9586 delete_optimizer_cost_module();
7448
7449
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9585 times.
9586 if (st) {
7450
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(ERROR_LEVEL, ER_PERFSCHEMA_TABLES_INIT_FAILED);
7451
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
1 unireg_abort(1);
7452 }
7453 }
7454 #endif
7455
7456
1/2
✓ Branch 0 taken 9603 times.
✗ Branch 1 not taken.
9603 bool recreate_non_dd_based_system_view = dd::upgrade::I_S_upgrade_required();
7457
6/6
✓ Branch 0 taken 9585 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 9383 times.
✓ Branch 3 taken 202 times.
✓ Branch 4 taken 185 times.
✓ Branch 5 taken 9418 times.
18986 if (!is_help_or_validate_option() && !opt_initialize &&
7458
3/4
✓ Branch 0 taken 9383 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 185 times.
✓ Branch 3 taken 9198 times.
9383 !dd::upgrade::no_server_upgrade_required()) {
7459
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 182 times.
185 if (opt_upgrade_mode == UPGRADE_MINIMAL)
7460
8/16
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
3 LogErr(WARNING_LEVEL, ER_SERVER_UPGRADE_SKIP);
7461 else {
7462
1/2
✓ Branch 0 taken 182 times.
✗ Branch 1 not taken.
182 init_optimizer_cost_module(true);
7463
2/4
✓ Branch 0 taken 182 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 182 times.
182 if (bootstrap::run_bootstrap_thread(nullptr, nullptr,
7464 &dd::upgrade::upgrade_system_schemas,
7465 SYSTEM_THREAD_SERVER_UPGRADE)) {
7466 LogErr(ERROR_LEVEL, ER_SERVER_UPGRADE_FAILED);
7467 unireg_abort(MYSQLD_ABORT_EXIT);
7468 }
7469
1/2
✓ Branch 0 taken 182 times.
✗ Branch 1 not taken.
182 delete_optimizer_cost_module();
7470 182 recreate_non_dd_based_system_view = true;
7471
7472 /*
7473 When upgrade is finished, we need to initialize the plugins that
7474 had their initialization delayed due to dependencies on the
7475 environment.
7476
7477 TODO: Provide a better long term solution by re-ordering startup
7478 sequence and rewriting the way we create and upgrade server
7479 resources needed by plugins.
7480 */
7481
2/4
✓ Branch 0 taken 182 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 182 times.
182 if (dd::upgrade::plugin_initialize_delayed_after_upgrade()) {
7482 unireg_abort(MYSQLD_ABORT_EXIT);
7483 }
7484 }
7485 }
7486
7487 /*
7488 Re-create non DD based system views after a) if we upgraded system
7489 schemas b) I_S system view version is changed and server system views
7490 were recreated. c) If the database was upgraded. We do not update this
7491 in upgrade-minimal mode.
7492 */
7493
2/2
✓ Branch 0 taken 9383 times.
✓ Branch 1 taken 202 times.
19188 if (!is_help_or_validate_option() && !opt_initialize &&
7494
8/8
✓ Branch 0 taken 9585 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 9380 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 182 times.
✓ Branch 5 taken 9198 times.
✓ Branch 6 taken 182 times.
✓ Branch 7 taken 9421 times.
19188 opt_upgrade_mode != UPGRADE_MINIMAL &&
7495 recreate_non_dd_based_system_view) {
7496
2/4
✓ Branch 0 taken 182 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 182 times.
182 if (dd::init(
7497 dd::enum_dd_init_type::DD_INITIALIZE_NON_DD_BASED_SYSTEM_VIEWS)) {
7498 LogErr(ERROR_LEVEL, ER_SYSTEM_VIEW_INIT_FAILED);
7499 unireg_abort(MYSQLD_ABORT_EXIT);
7500 }
7501 }
7502
7503
1/2
✓ Branch 0 taken 9603 times.
✗ Branch 1 not taken.
9603 auto res_grp_mgr = resourcegroups::Resource_group_mgr::instance();
7504 // Initialize the Resource group subsystem.
7505
6/6
✓ Branch 0 taken 9585 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 9383 times.
✓ Branch 3 taken 202 times.
✓ Branch 4 taken 9383 times.
✓ Branch 5 taken 220 times.
9603 if (!is_help_or_validate_option() && !opt_initialize) {
7506
2/4
✓ Branch 0 taken 9383 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9383 times.
9383 if (res_grp_mgr->post_init()) {
7507 LogErr(ERROR_LEVEL, ER_RESOURCE_GROUP_POST_INIT_FAILED);
7508 unireg_abort(MYSQLD_ABORT_EXIT);
7509 }
7510 }
7511
7512 Session_tracker session_track_system_variables_check;
7513 LEX_STRING var_list;
7514 char *tmp_str;
7515 9603 size_t len = strlen(global_system_variables.track_sysvars_ptr);
7516
1/2
✓ Branch 0 taken 9603 times.
✗ Branch 1 not taken.
9603 tmp_str = (char *)my_malloc(PSI_NOT_INSTRUMENTED, len * sizeof(char) + 2,
7517 MYF(MY_WME));
7518 9603 strcpy(tmp_str, global_system_variables.track_sysvars_ptr);
7519 9603 var_list.length = len;
7520 9603 var_list.str = tmp_str;
7521
2/4
✓ Branch 0 taken 9603 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9603 times.
9603 if (session_track_system_variables_check.server_boot_verify(
7522 system_charset_info, var_list)) {
7523 LogErr(ERROR_LEVEL, ER_TRACK_VARIABLES_BOGUS);
7524 if (tmp_str) my_free(tmp_str);
7525 unireg_abort(MYSQLD_ABORT_EXIT);
7526 }
7527
2/4
✓ Branch 0 taken 9603 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9603 times.
✗ Branch 3 not taken.
9603 if (tmp_str) my_free(tmp_str);
7528
7529 // Validate the configuration if --validate-config was specified.
7530
3/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 9598 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
9603 if (opt_validate_config && (remaining_argc > 1)) {
7531 5 bool saved_getopt_skip_unknown = my_getopt_skip_unknown;
7532 5 struct my_option no_opts[] = {{nullptr, 0, nullptr, nullptr, nullptr,
7533 nullptr, GET_NO_ARG, NO_ARG, 0, 0, 0,
7534 nullptr, 0, nullptr}};
7535
7536 5 my_getopt_skip_unknown = false;
7537
7538
3/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 3 times.
5 if (handle_options(&remaining_argc, &remaining_argv, no_opts,
7539 mysqld_get_one_option))
7540
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
2 unireg_abort(MYSQLD_ABORT_EXIT);
7541 3 my_getopt_skip_unknown = saved_getopt_skip_unknown;
7542 }
7543
7544
2/4
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 9585 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9601 if (is_help_or_validate_option()) unireg_abort(MYSQLD_SUCCESS_EXIT);
7545
7546 /* if the errmsg.sys is not loaded, terminate to maintain behaviour */
7547
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9585 times.
9585 if (!my_default_lc_messages->errmsgs->is_loaded()) {
7548 LogErr(ERROR_LEVEL, ER_CANT_READ_ERRMSGS);
7549 unireg_abort(MYSQLD_ABORT_EXIT);
7550 }
7551
7552
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 9575 times.
9585 if (opt_libcoredumper) {
7553 #if HAVE_LIBCOREDUMPER
7554
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (opt_corefile) {
7555 sql_print_warning(
7556 "Started with --core-file and --coredumper. "
7557 "--coredumper will take precedence.");
7558 }
7559
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if (opt_libcoredumper_path != NULL) {
7560
2/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
10 if (!validate_libcoredumper_path(opt_libcoredumper_path)) {
7561
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
10 unireg_abort(MYSQLD_ABORT_EXIT);
7562 }
7563 }
7564 #else
7565 sql_print_warning(
7566 "This version of MySQL has not been compiled with "
7567 "libcoredumper support, ignoring --coredumper argument");
7568 #endif
7569 }
7570
7571 /* We have to initialize the storage engines before CSV logging */
7572
2/4
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9575 times.
9575 if (ha_init()) {
7573 LogErr(ERROR_LEVEL, ER_CANT_INIT_DBS);
7574 unireg_abort(MYSQLD_ABORT_EXIT);
7575 }
7576
7577 /* Initialize ndbinfo tables in DD */
7578
2/4
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9575 times.
9575 if (dd::ndbinfo::init_schema_and_tables(opt_upgrade_mode)) {
7579 LogErr(ERROR_LEVEL, ER_NDBINFO_UPGRADING_SCHEMA_FAIL);
7580 unireg_abort(1);
7581 }
7582
7583
2/2
✓ Branch 0 taken 202 times.
✓ Branch 1 taken 9373 times.
9575 if (opt_initialize) log_output_options = LOG_FILE;
7584
7585 /*
7586 Issue a warning if there were specified additional options to the
7587 log-output along with NONE. Probably this wasn't what user wanted.
7588 */
7589
3/4
✓ Branch 0 taken 311 times.
✓ Branch 1 taken 9264 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 311 times.
9575 if ((log_output_options & LOG_NONE) && (log_output_options & ~LOG_NONE))
7590 LogErr(WARNING_LEVEL, ER_LOG_OUTPUT_CONTRADICTORY);
7591
7592
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9574 times.
9575 if (log_output_options & LOG_TABLE) {
7593 /* Fall back to log files if the csv engine is not loaded. */
7594 1 LEX_CSTRING csv_name = {STRING_WITH_LEN("csv")};
7595
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 if (!plugin_is_ready(csv_name, MYSQL_STORAGE_ENGINE_PLUGIN)) {
7596 LogErr(ERROR_LEVEL, ER_NO_CSV_NO_LOG_TABLES);
7597 log_output_options = (log_output_options & ~LOG_TABLE) | LOG_FILE;
7598 }
7599 }
7600
7601
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 query_logger.set_handlers(log_output_options);
7602
7603 // Open slow log file if enabled.
7604
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 query_logger.set_log_file(QUERY_LOG_SLOW);
7605
7/8
✓ Branch 0 taken 8929 times.
✓ Branch 1 taken 646 times.
✓ Branch 2 taken 8929 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 8928 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 9574 times.
9575 if (opt_slow_log && query_logger.reopen_log_file(QUERY_LOG_SLOW))
7606 1 opt_slow_log = false;
7607
7608 // Open general log file if enabled.
7609
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 query_logger.set_log_file(QUERY_LOG_GENERAL);
7610
7/8
✓ Branch 0 taken 8929 times.
✓ Branch 1 taken 646 times.
✓ Branch 2 taken 8929 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 8928 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 9574 times.
9575 if (opt_general_log && query_logger.reopen_log_file(QUERY_LOG_GENERAL))
7611 1 opt_general_log = false;
7612
7613 /*
7614 Set the default storage engines
7615 */
7616
2/4
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9575 times.
9575 if (initialize_storage_engine(default_storage_engine, "",
7617 &global_system_variables.table_plugin))
7618 unireg_abort(MYSQLD_ABORT_EXIT);
7619
2/4
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9575 times.
9575 if (initialize_storage_engine(default_tmp_storage_engine, " temp",
7620 &global_system_variables.temp_table_plugin))
7621 unireg_abort(MYSQLD_ABORT_EXIT);
7622
7623 #ifdef WITH_WSREP
7624 /* Turn on emulation based binlogging if log-bin is OFF */
7625
2/2
✓ Branch 0 taken 465 times.
✓ Branch 1 taken 9110 times.
9575 if (!opt_bin_log) wsrep_emulate_bin_log = 1;
7626 #endif /* WITH_WSREP */
7627
7628
4/4
✓ Branch 0 taken 9373 times.
✓ Branch 1 taken 202 times.
✓ Branch 2 taken 9359 times.
✓ Branch 3 taken 14 times.
9575 if (!opt_initialize && !opt_noacl) {
7629
1/2
✓ Branch 0 taken 9359 times.
✗ Branch 1 not taken.
9359 set_externally_disabled_storage_engine_names(opt_disabled_storage_engines);
7630
7631 // Log warning if default_storage_engine is a disabled storage engine.
7632 handlerton *default_se_handle =
7633 9359 plugin_data<handlerton *>(global_system_variables.table_plugin);
7634
3/4
✓ Branch 0 taken 9359 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 9355 times.
9359 if (ha_is_storage_engine_disabled(default_se_handle))
7635
8/16
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 4 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 4 times.
✗ Branch 15 not taken.
4 LogErr(WARNING_LEVEL, ER_DISABLED_STORAGE_ENGINE_AS_DEFAULT,
7636 "default_storage_engine", default_storage_engine);
7637
7638 // Log warning if default_tmp_storage_engine is a disabled storage engine.
7639 handlerton *default_tmp_se_handle =
7640 9359 plugin_data<handlerton *>(global_system_variables.temp_table_plugin);
7641
3/4
✓ Branch 0 taken 9359 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 9355 times.
9359 if (ha_is_storage_engine_disabled(default_tmp_se_handle))
7642
8/16
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 4 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 4 times.
✗ Branch 15 not taken.
4 LogErr(WARNING_LEVEL, ER_DISABLED_STORAGE_ENGINE_AS_DEFAULT,
7643 "default_tmp_storage_engine", default_tmp_storage_engine);
7644 }
7645
7646 /*
7647 Validate any enforced storage engine
7648 */
7649
4/6
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 9568 times.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
9575 if (enforce_storage_engine && !opt_initialize && !opt_noacl) {
7650 const LEX_CSTRING name{enforce_storage_engine,
7651 7 strlen(enforce_storage_engine)};
7652 plugin_ref plugin;
7653
2/4
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
7 if ((plugin = ha_resolve_by_name(nullptr, &name, false))) {
7654 7 handlerton *hton = plugin_data<handlerton *>(plugin);
7655 const LEX_CSTRING defname{default_storage_engine,
7656 7 strlen(default_storage_engine)};
7657 plugin_ref defplugin;
7658 handlerton *defhton;
7659
2/4
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
7 if ((defplugin = ha_resolve_by_name(nullptr, &defname, false))) {
7660 7 defhton = plugin_data<handlerton *>(defplugin);
7661
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
7 if (defhton != hton) {
7662
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 sql_print_warning(
7663 "Default storage engine (%s)"
7664 " is not the same as enforced storage engine (%s)",
7665 default_storage_engine, enforce_storage_engine);
7666 }
7667 }
7668
3/4
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 6 times.
7 if (ha_is_storage_engine_disabled(hton)) {
7669
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 sql_print_error(
7670 "enforced storage engine %s is among disabled storage "
7671 "engines",
7672 enforce_storage_engine);
7673
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
1 unireg_abort(MYSQLD_ABORT_EXIT);
7674 }
7675
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 plugin_unlock(nullptr, defplugin);
7676
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 plugin_unlock(nullptr, plugin);
7677 } else {
7678 sql_print_error("Unknown/unsupported storage engine: %s",
7679 enforce_storage_engine);
7680 unireg_abort(MYSQLD_ABORT_EXIT);
7681 }
7682 }
7683
7684
3/4
✓ Branch 0 taken 9574 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 9573 times.
9574 DBUG_EXECUTE_IF("total_ha_2pc_equals_2", total_ha_2pc = 2;);
7685
4/6
✓ Branch 0 taken 251 times.
✓ Branch 1 taken 9323 times.
✓ Branch 2 taken 251 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 251 times.
9574 if (total_ha_2pc > 1 || (1 == total_ha_2pc && opt_bin_log)) {
7686
2/2
✓ Branch 0 taken 9109 times.
✓ Branch 1 taken 214 times.
9323 if (opt_bin_log)
7687 9109 tc_log = &mysql_bin_log;
7688 else
7689 #ifdef WITH_WSREP
7690 /*
7691 wsrep hton grows total_ha_2pc count to 2, even in native mysql mode.
7692 Have to force using tc_log_dummy here, as tc_log_mmap segfaults
7693 */
7694 214 tc_log = &tc_log_dummy;
7695 #else
7696 tc_log = &tc_log_mmap;
7697 #endif /* WITH_WSREP */
7698 }
7699
7700 #ifdef WITH_WSREP
7701
13/30
✓ Branch 0 taken 58 times.
✓ Branch 1 taken 9516 times.
✓ Branch 2 taken 58 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 58 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 58 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 58 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 58 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 58 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 58 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 58 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 58 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 58 times.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 58 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
9574 WSREP_DEBUG("Initial TC log open: %s",
7702 (tc_log == &mysql_bin_log)
7703 ? "binlog"
7704 : (tc_log == &tc_log_mmap)
7705 ? "mmap"
7706 : (tc_log == &tc_log_dummy) ? "dummy" : "unknown");
7707 #endif /* WITH_WSREP */
7708
7709
2/4
✓ Branch 0 taken 9574 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9574 times.
9574 if (Recovered_xa_transactions::init()) {
7710 LogErr(ERROR_LEVEL, ER_OOM);
7711 unireg_abort(MYSQLD_ABORT_EXIT);
7712 }
7713
7714
4/6
✓ Branch 0 taken 9574 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1506 times.
✓ Branch 3 taken 8068 times.
✓ Branch 4 taken 1506 times.
✗ Branch 5 not taken.
9574 RUN_HOOK(server_state, before_recovery, (nullptr));
7715
5/6
✓ Branch 0 taken 9109 times.
✓ Branch 1 taken 465 times.
✓ Branch 2 taken 9574 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 81 times.
✓ Branch 5 taken 9493 times.
9574 if (tc_log->open(opt_bin_log ? opt_bin_logname : opt_tc_log_file)) {
7716
8/16
✓ Branch 0 taken 81 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 81 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 81 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 81 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 81 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 81 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 81 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 81 times.
✗ Branch 15 not taken.
81 LogErr(ERROR_LEVEL, ER_CANT_INIT_TC_LOG);
7717
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
81 unireg_abort(MYSQLD_ABORT_EXIT);
7718 }
7719
7720
2/4
✓ Branch 0 taken 9493 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9493 times.
9493 if (dd::reset_tables_and_tablespaces()) {
7721 unireg_abort(MYSQLD_ABORT_EXIT);
7722 }
7723
1/2
✓ Branch 0 taken 9489 times.
✗ Branch 1 not taken.
9493 ha_post_recover();
7724
7725 /*
7726 Add prepared XA transactions into the cache of XA transactions and acquire
7727 mdl lock for every table involved in any of these prepared XA transactions.
7728 This step moved away from the function ha_recover() in order to avoid
7729 possible suspending on acquiring EXCLUSIVE mdl lock on tables inside the
7730 function dd::reset_tables_and_tablespaces() when table cache being reset.
7731 */
7732
1/2
✓ Branch 0 taken 9489 times.
✗ Branch 1 not taken.
9489 if (Recovered_xa_transactions::instance()
7733
2/4
✓ Branch 0 taken 9489 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9489 times.
9489 .recover_prepared_xa_transactions()) {
7734 unireg_abort(MYSQLD_ABORT_EXIT);
7735 }
7736
7737 #ifdef WITH_WSREP
7738
2/2
✓ Branch 0 taken 9473 times.
✓ Branch 1 taken 16 times.
9489 if (!wsrep_recovery) {
7739 #endif /* WITH_WSREP */
7740
5/6
✓ Branch 0 taken 9473 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2200 times.
✓ Branch 3 taken 7273 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 9470 times.
11673 if (global_gtid_mode.get() == Gtid_mode::ON &&
7741
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2197 times.
2200 _gtid_consistency_mode != GTID_CONSISTENCY_MODE_ON) {
7742
8/16
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
3 LogErr(ERROR_LEVEL,
7743 ER_RPL_GTID_MODE_REQUIRES_ENFORCE_GTID_CONSISTENCY_ON);
7744
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
3 unireg_abort(MYSQLD_ABORT_EXIT);
7745 }
7746 #ifdef WITH_WSREP
7747 }
7748 #endif /* WITH_WSREP */
7749
7750
3/4
✓ Branch 0 taken 9486 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 9474 times.
9486 if (rpl_encryption.initialize()) {
7751
8/16
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 12 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 12 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 12 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 12 times.
✗ Branch 15 not taken.
12 LogErr(ERROR_LEVEL, ER_SERVER_RPL_ENCRYPTION_UNABLE_TO_INITIALIZE);
7752
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
12 unireg_abort(MYSQLD_ABORT_EXIT);
7753 }
7754
7755
7/8
✓ Branch 0 taken 9474 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 79 times.
✓ Branch 3 taken 9395 times.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 75 times.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 9470 times.
9474 if (rpl_encryption.is_enabled() && !opt_bin_log) {
7756
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 sql_print_information(
7757 "binlog and relay log encryption enabled without binary logging being "
7758 "enabled. "
7759 "If relay logs are in use, they will be encrypted.");
7760 }
7761
7762 #ifdef WITH_WSREP
7763 /* Don't spawn a new binlog file during wsrep-recovery. Why ?
7764 - Recovery flow is only going to read existing wsrep saved co-ordinate
7765 from sys_header. No other action is performed that needs binlogging.
7766
7767 - Existing server flow looks at last binlog to set gtid_executed if server
7768 was shutdown abruptly. Newly create binlog will not have any such
7769 information and so restart post wsrep_recover will result in gtid_executed
7770 to be empty. */
7771
4/4
✓ Branch 0 taken 9009 times.
✓ Branch 1 taken 465 times.
✓ Branch 2 taken 8993 times.
✓ Branch 3 taken 16 times.
9474 if (opt_bin_log && !wsrep_recovery) {
7772 #else
7773 if (opt_bin_log) {
7774 #endif /* WITH_WSREP */
7775 /*
7776 Configures what object is used by the current log to store processed
7777 gtid(s). This is necessary in the MYSQL_BIN_LOG::MYSQL_BIN_LOG to
7778 correctly compute the set of previous gtids.
7779 */
7780
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8993 times.
8993 assert(!mysql_bin_log.is_relay_log);
7781 8993 mysql_mutex_t *log_lock = mysql_bin_log.get_log_lock();
7782
1/2
✓ Branch 0 taken 8993 times.
✗ Branch 1 not taken.
8993 mysql_mutex_lock(log_lock);
7783
7784
3/4
✓ Branch 0 taken 8993 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8991 times.
8993 if (mysql_bin_log.open_binlog(opt_bin_logname, nullptr, max_binlog_size,
7785 false, true /*need_lock_index=true*/,
7786 true /*need_sid_lock=true*/, nullptr)) {
7787
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 mysql_mutex_unlock(log_lock);
7788
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
2 unireg_abort(MYSQLD_ABORT_EXIT);
7789 }
7790
1/2
✓ Branch 0 taken 8991 times.
✗ Branch 1 not taken.
8991 mysql_mutex_unlock(log_lock);
7791 }
7792
7793 #ifdef WITH_WSREP
7794 /* In wsrep_recovery mode, PXC avoid creation of new binlog file for
7795 the reason mentioned above. In light of the said flow avoid purge
7796 action on binlog. */
7797
2/2
✓ Branch 0 taken 9456 times.
✓ Branch 1 taken 16 times.
9472 if (!wsrep_recovery) {
7798 #endif /* WITH_WSREP */
7799 /*
7800 When we pass non-zero values for both expire_logs_days and
7801 binlog_expire_logs_seconds at the server start-up, the value of
7802 expire_logs_days will be ignored and only binlog_expire_logs_seconds
7803 will be used.
7804 */
7805
4/4
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 9434 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 8 times.
9456 if (binlog_expire_logs_seconds_supplied && expire_logs_days_supplied) {
7806
4/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 5 times.
14 if (binlog_expire_logs_seconds != 0 && expire_logs_days != 0) {
7807
8/16
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
3 LogErr(WARNING_LEVEL, ER_EXPIRE_LOGS_DAYS_IGNORED);
7808 3 expire_logs_days = 0;
7809 }
7810
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 9434 times.
9442 } else if (expire_logs_days_supplied)
7811 8 binlog_expire_logs_seconds = 0;
7812
3/4
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 9449 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
9456 assert(expire_logs_days == 0 || binlog_expire_logs_seconds == 0);
7813
7814
2/2
✓ Branch 0 taken 8991 times.
✓ Branch 1 taken 465 times.
9456 if (opt_bin_log) {
7815
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 8987 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
8991 if (binlog_space_limit) mysql_bin_log.purge_logs_by_size(true);
7816 } else {
7817
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 458 times.
465 if (binlog_expire_logs_seconds_supplied)
7818
8/16
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 7 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 7 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 7 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 7 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 7 times.
✗ Branch 15 not taken.
7 LogErr(WARNING_LEVEL, ER_NEED_LOG_BIN, "--binlog-expire-logs-seconds");
7819
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 459 times.
465 if (expire_logs_days_supplied)
7820
8/16
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 6 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 6 times.
✗ Branch 15 not taken.
6 LogErr(WARNING_LEVEL, ER_NEED_LOG_BIN, "--expire_logs_days");
7821
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 465 times.
465 if (binlog_space_limit)
7822 LogErr(WARNING_LEVEL, ER_NEED_LOG_BIN, "--binlog-space-limit");
7823 }
7824 #ifdef WITH_WSREP
7825 }
7826 #endif /* WITH_WSREP */
7827
7828
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9472 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9472 if (opt_myisam_log) (void)mi_log(1);
7829
7830 #if defined(HAVE_MLOCKALL) && defined(MCL_CURRENT)
7831
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 9472 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9472 times.
9472 if (locked_in_memory && !getuid()) {
7832 if (setreuid((uid_t)-1, 0) == -1) { // this should never happen
7833 LogErr(ERROR_LEVEL, ER_FAIL_SETREUID, strerror(errno));
7834 unireg_abort(MYSQLD_ABORT_EXIT);
7835 }
7836 if (mlockall(MCL_CURRENT)) {
7837 LogErr(WARNING_LEVEL, ER_FAILED_TO_LOCK_MEM,
7838 errno); /* purecov: inspected */
7839 locked_in_memory = false;
7840 }
7841 #ifndef _WIN32
7842 if (!user_info.IsVoid()) set_user(mysqld_user, user_info);
7843 #endif
7844 } else
7845 #endif
7846 9472 locked_in_memory = false;
7847
7848
2/4
✓ Branch 0 taken 9472 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9472 times.
✗ Branch 3 not taken.
9472 rpl_acf_configuration_handler = new Rpl_acf_configuration_handler();
7849
2/4
✓ Branch 0 taken 9472 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9472 times.
9472 if (rpl_acf_configuration_handler->init()) {
7850 unireg_abort(MYSQLD_ABORT_EXIT);
7851 }
7852
2/4
✓ Branch 0 taken 9472 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9472 times.
✗ Branch 3 not taken.
9472 rpl_source_io_monitor = new Source_IO_monitor();
7853
1/2
✓ Branch 0 taken 9472 times.
✗ Branch 1 not taken.
9472 udf_load_service.init();
7854
7855 /* Initialize the optimizer cost module */
7856
1/2
✓ Branch 0 taken 9472 times.
✗ Branch 1 not taken.
9472 init_optimizer_cost_module(true);
7857
1/2
✓ Branch 0 taken 9472 times.
✗ Branch 1 not taken.
9472 ft_init_stopwords();
7858
7859
1/2
✓ Branch 0 taken 9472 times.
✗ Branch 1 not taken.
9472 init_max_user_conn();
7860
7861
1/2
✓ Branch 0 taken 9472 times.
✗ Branch 1 not taken.
9472 init_global_user_stats();
7862
1/2
✓ Branch 0 taken 9472 times.
✗ Branch 1 not taken.
9472 init_global_client_stats();
7863
1/2
✓ Branch 0 taken 9472 times.
✗ Branch 1 not taken.
9472 init_global_thread_stats();
7864
7865 #if defined(MYSQL_ICU_DATADIR)
7866
1/2
✓ Branch 0 taken 9472 times.
✗ Branch 1 not taken.
9472 init_icu_data_directory();
7867 #endif // MYSQL_ICU_DATADIR
7868
7869 9472 return 0;
7870 9472 }
7871
7872 #ifdef _WIN32
7873
7874 extern "C" void *handle_shutdown_and_restart(void *arg) {
7875 MSG msg;
7876 HANDLE event_handles[2];
7877 event_handles[0] = hEventShutdown;
7878 event_handles[1] = hEventRestart;
7879
7880 my_thread_init();
7881 /* This call should create the message queue for this thread. */
7882 PeekMessage(&msg, NULL, 1, 65534, PM_NOREMOVE);
7883 DWORD ret_code = WaitForMultipleObjects(
7884 2, static_cast<HANDLE *>(event_handles), FALSE, INFINITE);
7885
7886 if (ret_code == WAIT_OBJECT_0 || ret_code == WAIT_OBJECT_0 + 1) {
7887 if (ret_code == WAIT_OBJECT_0)
7888 LogErr(SYSTEM_LEVEL, ER_NORMAL_SERVER_SHUTDOWN, my_progname);
7889 else
7890 signal_hand_thr_exit_code = MYSQLD_RESTART_EXIT;
7891
7892 set_connection_events_loop_aborted(true);
7893 close_connections();
7894 my_thread_end();
7895 my_thread_exit(0);
7896 }
7897 return 0;
7898 }
7899
7900 static void create_shutdown_and_restart_thread() {
7901 DBUG_TRACE;
7902
7903 const char *errmsg;
7904 my_thread_attr_t thr_attr;
7905 SECURITY_ATTRIBUTES *shutdown_sec_attr;
7906
7907 my_security_attr_create(&shutdown_sec_attr, &errmsg, GENERIC_ALL,
7908 SYNCHRONIZE | EVENT_MODIFY_STATE);
7909
7910 if (!opt_no_monitor) {
7911 snprintf(shutdown_event_name, sizeof(shutdown_event_name),
7912 "mysqld%s_shutdown", get_monitor_pid());
7913 }
7914
7915 hEventShutdown =
7916 CreateEvent(shutdown_sec_attr, FALSE, FALSE, shutdown_event_name);
7917 hEventRestart = CreateEvent(0, FALSE, FALSE, restart_event_name);
7918
7919 my_thread_attr_init(&thr_attr);
7920
7921 if (my_thread_create(&shutdown_restart_thr_handle, &thr_attr,
7922 handle_shutdown_and_restart, 0))
7923 LogErr(WARNING_LEVEL, ER_CANT_CREATE_SHUTDOWN_THREAD, errno);
7924
7925 my_security_attr_free(shutdown_sec_attr);
7926 my_thread_attr_destroy(&thr_attr);
7927 }
7928 #endif /* _WIN32 */
7929
7930 #ifndef NDEBUG
7931 /*
7932 Debugging helper function to keep the locale database
7933 (see sql_locale.cc) and max_month_name_length and
7934 max_day_name_length variable values in consistent state.
7935 */
7936 9770 static void test_lc_time_sz() {
7937
1/2
✓ Branch 0 taken 9770 times.
✗ Branch 1 not taken.
9770 DBUG_TRACE;
7938
2/2
✓ Branch 0 taken 1084470 times.
✓ Branch 1 taken 9770 times.
1094240 for (MY_LOCALE **loc = my_locales; *loc; loc++) {
7939 1084470 size_t max_month_len = 0;
7940 1084470 size_t max_day_len = 0;
7941
2/2
✓ Branch 0 taken 13013640 times.
✓ Branch 1 taken 1084470 times.
14098110 for (const char **month = (*loc)->month_names->type_names; *month;
7942 month++) {
7943 26027280 max_month_len = std::max(
7944 13013640 max_month_len, my_numchars_mb(&my_charset_utf8_general_ci, *month,
7945
1/2
✓ Branch 0 taken 13013640 times.
✗ Branch 1 not taken.
13013640 *month + strlen(*month)));
7946 }
7947
2/2
✓ Branch 0 taken 7591290 times.
✓ Branch 1 taken 1084470 times.
8675760 for (const char **day = (*loc)->day_names->type_names; *day; day++) {
7948 7591290 max_day_len =
7949 7591290 std::max(max_day_len, my_numchars_mb(&my_charset_utf8_general_ci,
7950
1/2
✓ Branch 0 taken 7591290 times.
✗ Branch 1 not taken.
7591290 *day, *day + strlen(*day)));
7951 }
7952
1/2
✓ Branch 0 taken 1084470 times.
✗ Branch 1 not taken.
1084470 if ((*loc)->max_month_name_length != max_month_len ||
7953
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1084470 times.
1084470 (*loc)->max_day_name_length != max_day_len) {
7954 DBUG_PRINT("Wrong max day name(or month name) length for locale:",
7955 ("%s", (*loc)->name));
7956 assert(0);
7957 }
7958 }
7959 9770 }
7960 #endif // NDEBUG
7961
7962 /*
7963 @brief : Set opt_super_readonly to user supplied value before
7964 enabling communication channels to accept user connections
7965 */
7966
7967 9177 static void set_super_read_only_post_init() {
7968 9177 opt_super_readonly = super_read_only;
7969 9177 }
7970
7971 10136 static void calculate_mysql_home_from_my_progname() {
7972 const std::string runtime_output_directory_addon{
7973
1/2
✓ Branch 0 taken 10136 times.
✗ Branch 1 not taken.
10136 "/runtime_output_directory/"};
7974 #if defined(_WIN32) || defined(APPLE_XCODE)
7975 /* Allow Win32 users to move MySQL anywhere */
7976 char prg_dev[FN_REFLEN];
7977 my_path(prg_dev, my_progname, nullptr);
7978
7979 // On windows or Xcode the basedir will always be one level up from where
7980 // the executable is located. E.g. <basedir>/bin/mysqld.exe in a
7981 // package, or <basedir>/runtime_output_directory/<buildconfig>/mysqld.exe
7982 // for a sandbox build.
7983 strcat(prg_dev, "/../"); // Remove containing directory to get base dir
7984 cleanup_dirname(mysql_home, prg_dev);
7985
7986 // New layout: <cmake_binary_dir>/runtime_output_directory/<buildconfig>/
7987 char cmake_binary_dir[FN_REFLEN];
7988 size_t dlen = 0;
7989 dirname_part(cmake_binary_dir, mysql_home, &dlen);
7990 if (dlen > runtime_output_directory_addon.length() &&
7991 (!strcmp(
7992 cmake_binary_dir + (dlen - runtime_output_directory_addon.length()),
7993 runtime_output_directory_addon.c_str()) ||
7994 !strcmp(
7995 cmake_binary_dir + (dlen - runtime_output_directory_addon.length()),
7996 "\\runtime_output_directory\\"))) {
7997 mysql_home[strlen(mysql_home) - 1] = '\0'; // remove trailing
7998 dirname_part(cmake_binary_dir, mysql_home, &dlen);
7999 strmake(mysql_home, cmake_binary_dir, sizeof(mysql_home) - 1);
8000 }
8001 // The sql_print_information below outputs nothing ??
8002 // fprintf(stderr, "mysql_home %s\n", mysql_home);
8003 // fflush(stderr);
8004 #else
8005 10136 const char *tmpenv = getenv("MY_BASEDIR_VERSION");
8006
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10136 times.
10136 if (tmpenv != nullptr) {
8007 strmake(mysql_home, tmpenv, sizeof(mysql_home) - 1);
8008 } else {
8009 char progdir[FN_REFLEN];
8010 10136 size_t dlen = 0;
8011
1/2
✓ Branch 0 taken 10136 times.
✗ Branch 1 not taken.
10136 dirname_part(progdir, my_progname, &dlen);
8012
3/4
✓ Branch 0 taken 10136 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10135 times.
✓ Branch 3 taken 1 times.
20272 if (dlen > runtime_output_directory_addon.length() &&
8013
2/2
✓ Branch 0 taken 10135 times.
✓ Branch 1 taken 1 times.
10136 !strcmp(progdir + (dlen - runtime_output_directory_addon.length()),
8014 runtime_output_directory_addon.c_str())) {
8015 char cmake_binary_dir[FN_REFLEN];
8016 10135 progdir[strlen(progdir) - 1] = '\0'; // remove trailing "/"
8017
1/2
✓ Branch 0 taken 10135 times.
✗ Branch 1 not taken.
10135 dirname_part(cmake_binary_dir, progdir, &dlen);
8018
1/2
✓ Branch 0 taken 10135 times.
✗ Branch 1 not taken.
10135 strmake(mysql_home, cmake_binary_dir, sizeof(mysql_home) - 1);
8019 } else {
8020 1 strcat(progdir, "/../");
8021
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 cleanup_dirname(mysql_home, progdir);
8022 }
8023 }
8024 #endif
8025 10136 mysql_home_ptr = mysql_home;
8026 10136 }
8027
8028 /**
8029 Helper class for loading keyring component
8030 Keyring component is loaded after minimal chassis initialization.
8031 At this time, home dir and plugin dir may not be initialized.
8032
8033 This helper class sets them temporarily by reading configurations
8034 and resets them in destructor.
8035 */
8036 class Plugin_and_data_dir_option_parser final {
8037 public:
8038 9813 Plugin_and_data_dir_option_parser(int argc, char **argv)
8039 9813 : datadir_(nullptr),
8040 9813 plugindir_(nullptr),
8041 9813 save_homedir_{0},
8042 9813 save_plugindir_{0},
8043 9813 valid_(false) {
8044 9813 char *ptr, **res, *datadir = nullptr, *plugindir = nullptr;
8045 9813 char dir[FN_REFLEN] = {0}, local_datadir_buffer[FN_REFLEN] = {0},
8046 9813 local_plugindir_buffer[FN_REFLEN] = {0};
8047 9813 const char *dirs = nullptr;
8048
8049 9813 my_option datadir_options[] = {
8050 {"datadir", 0, "", &datadir, nullptr, nullptr, GET_STR, OPT_ARG, 0, 0,
8051 0, nullptr, 0, nullptr},
8052 {"plugin_dir", 0, "", &plugindir, nullptr, nullptr, GET_STR, OPT_ARG, 0,
8053 0, 0, nullptr, 0, nullptr},
8054 {nullptr, 0, nullptr, nullptr, nullptr, nullptr, GET_NO_ARG, NO_ARG, 0,
8055 9813 0, 0, nullptr, 0, nullptr}};
8056
8057 /*
8058 create temporary args list and pass it to handle_options.
8059 We do this because we don't want to mess with the actual
8060 argument list. handle_options() trims the processed parts.
8061 */
8062 9813 MEM_ROOT alloc{PSI_NOT_INSTRUMENTED, 512};
8063 9813 if (!(ptr =
8064
2/4
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9813 times.
9813 (char *)alloc.Alloc(sizeof(alloc) + (argc + 1) * sizeof(char *))))
8065 return;
8066 9813 memset(ptr, 0, (sizeof(char *) * (argc + 1)));
8067 9813 res = (char **)(ptr);
8068 9813 memcpy((uchar *)res, (char *)(argv), (argc) * sizeof(char *));
8069
8070 9813 my_getopt_skip_unknown = true;
8071
2/4
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9813 times.
9813 if (my_handle_options(&argc, &res, datadir_options, nullptr, nullptr,
8072 true)) {
8073 my_getopt_skip_unknown = false;
8074 return;
8075 }
8076 9813 my_getopt_skip_unknown = false;
8077
8078
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 9783 times.
9813 if (!datadir) {
8079 /* mysql_real_data_home must be initialized at this point */
8080
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 assert(mysql_real_data_home[0]);
8081 /*
8082 mysql_home_ptr should also be initialized at this point.
8083 See calculate_mysql_home_from_my_progname() for details
8084 */
8085
2/4
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
✗ Branch 3 not taken.
30 assert(mysql_home_ptr && mysql_home_ptr[0]);
8086
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 convert_dirname(local_datadir_buffer, mysql_real_data_home, NullS);
8087
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 (void)my_load_path(local_datadir_buffer, local_datadir_buffer,
8088 mysql_home_ptr);
8089 30 datadir = local_datadir_buffer;
8090 }
8091 9813 dirs = datadir;
8092
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 unpack_dirname(dir, dirs);
8093
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 datadir_ = my_strdup(PSI_INSTRUMENT_ME, dir, MYF(0));
8094 9813 memset(dir, 0, FN_REFLEN);
8095
8096
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 convert_dirname(local_plugindir_buffer,
8097
3/4
✓ Branch 0 taken 6196 times.
✓ Branch 1 taken 3617 times.
✓ Branch 2 taken 6196 times.
✗ Branch 3 not taken.
9813 plugindir ? plugindir : get_relative_path(PLUGINDIR),
8098 NullS);
8099
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 (void)my_load_path(local_plugindir_buffer, local_plugindir_buffer,
8100 mysql_home);
8101
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 plugindir_ = my_strdup(PSI_INSTRUMENT_ME, local_plugindir_buffer, MYF(0));
8102
8103 /* Backup mysql_real_data_home */
8104
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 if (mysql_real_data_home[0])
8105 9813 memcpy(save_homedir_, mysql_real_data_home, strlen(mysql_real_data_home));
8106
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 if (datadir_ != nullptr)
8107 9813 memcpy(mysql_real_data_home, datadir_, strlen(datadir_));
8108
8109 /* Backup opt_plugin_dir */
8110
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9813 times.
9813 if (opt_plugin_dir[0])
8111 memcpy(save_plugindir_, opt_plugin_dir,
8112 std::min(static_cast<size_t>(FN_REFLEN), strlen(opt_plugin_dir)));
8113
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 if (plugindir_ != nullptr)
8114 9813 memcpy(opt_plugin_dir, plugindir_, strlen(plugindir_));
8115
8116 9813 valid_ = true;
8117
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 }
8118
8119 9813 ~Plugin_and_data_dir_option_parser() {
8120 9813 valid_ = false;
8121
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 if (datadir_ != nullptr) {
8122 9813 memset(mysql_real_data_home, 0, sizeof(mysql_real_data_home));
8123 9813 memcpy(mysql_real_data_home, save_homedir_, strlen(save_homedir_));
8124 9813 my_free(datadir_);
8125 }
8126
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 if (plugindir_ != nullptr) {
8127 9813 memset(opt_plugin_dir, 0, sizeof(opt_plugin_dir));
8128 9813 memcpy(opt_plugin_dir, save_plugindir_, strlen(save_plugindir_));
8129 9813 my_free(plugindir_);
8130 }
8131 9813 }
8132
8133 9813 bool valid() const { return valid_; }
8134
8135 private:
8136 char *datadir_;
8137 char *plugindir_;
8138 char save_homedir_[FN_REFLEN + 1];
8139 char save_plugindir_[FN_REFLEN + 1];
8140 bool valid_;
8141 };
8142
8143 #ifdef _WIN32
8144 int win_main(int argc, char **argv)
8145 #else
8146 10136 int mysqld_main(int argc, char **argv)
8147 #endif
8148 {
8149 // Substitute the full path to the executable in argv[0]
8150
1/2
✓ Branch 0 taken 10136 times.
✗ Branch 1 not taken.
10136 substitute_progpath(argv);
8151
1/2
✓ Branch 0 taken 10136 times.
✗ Branch 1 not taken.
10136 sysd::notify_connect();
8152
1/2
✓ Branch 0 taken 10136 times.
✗ Branch 1 not taken.
10136 sysd::notify("STATUS=Server startup in progress\n");
8153
8154 /*
8155 Perform basic thread library and malloc initialization,
8156 to be able to read defaults files and parse options.
8157 */
8158 10136 my_progname = argv[0];
8159
1/2
✓ Branch 0 taken 10136 times.
✗ Branch 1 not taken.
10136 calculate_mysql_home_from_my_progname();
8160
8161 #ifndef _WIN32
8162 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
8163
1/2
✓ Branch 0 taken 10136 times.
✗ Branch 1 not taken.
10136 pre_initialize_performance_schema();
8164 #endif /*WITH_PERFSCHEMA_STORAGE_ENGINE */
8165 // For windows, my_init() is called from the win specific mysqld_main
8166
2/4
✓ Branch 0 taken 10136 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10136 times.
10136 if (my_init()) // init my_sys library & pthreads
8167 {
8168 LogErr(ERROR_LEVEL, ER_MYINIT_FAILED);
8169 flush_error_log_messages();
8170 return 1;
8171 }
8172 #endif /* _WIN32 */
8173 #ifdef WITH_WSREP
8174
1/2
✓ Branch 0 taken 10136 times.
✗ Branch 1 not taken.
10136 wsrep_filter_new_cluster(&argc, argv);
8175 #endif /* WITH_WSREP */
8176
8177 10136 orig_argc = argc;
8178 10136 orig_argv = argv;
8179 10136 my_getopt_use_args_separator = true;
8180 10136 my_defaults_read_login_file = false;
8181
3/4
✓ Branch 0 taken 10136 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 10130 times.
10136 if (load_defaults(MYSQL_CONFIG_NAME, load_default_groups, &argc, &argv,
8182 &argv_alloc)) {
8183
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 flush_error_log_messages();
8184 6 return 1;
8185 }
8186
8187 /* Set data dir directory paths */
8188
2/4
✓ Branch 0 taken 10130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10130 times.
✗ Branch 3 not taken.
10130 strmake(mysql_real_data_home, get_relative_path(MYSQL_DATADIR),
8189 sizeof(mysql_real_data_home) - 1);
8190
8191 /* Must be initialized early for comparison of options name */
8192 10130 system_charset_info = &my_charset_utf8_general_ci;
8193
8194 /* Write mysys error messages to the error log. */
8195 10130 local_message_hook = error_log_print;
8196
8197
1/2
✓ Branch 0 taken 10130 times.
✗ Branch 1 not taken.
10130 sys_var_init();
8198
8199 #ifdef _WIN32
8200 if (mysys::is_my_malloc_using_jemalloc()) {
8201 LogErr(INFORMATION_LEVEL, ER_MY_MALLOC_USING_JEMALLOC);
8202 } else {
8203 for (auto &msg : mysys::fetch_jemalloc_initialization_messages()) {
8204 LogErr(msg.m_severity, ER_MY_MALLOC_USING_JEMALLOC + msg.m_ecode,
8205 msg.m_message.c_str());
8206 }
8207 }
8208 #endif
8209 /*
8210 Initialize variables cache for persisted variables, load persisted
8211 config file and append parse early read only persisted variables
8212 to command line options if present.
8213 */
8214 10130 bool arg_separator_added = false;
8215
1/2
✓ Branch 0 taken 10130 times.
✗ Branch 1 not taken.
10130 if (persisted_variables_cache.init(&argc, &argv) ||
8216
6/8
✓ Branch 0 taken 10130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10130 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10124 times.
✓ Branch 5 taken 6 times.
✓ Branch 6 taken 6 times.
✓ Branch 7 taken 10124 times.
20254 persisted_variables_cache.load_persist_file() ||
8217
2/4
✓ Branch 0 taken 10124 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10124 times.
10124 persisted_variables_cache.append_parse_early_variables(
8218 &argc, &argv, arg_separator_added)) {
8219
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 flush_error_log_messages();
8220 6 return 1;
8221 }
8222
8223 10124 remaining_argc = argc;
8224 10124 remaining_argv = argv;
8225
8226
1/2
✓ Branch 0 taken 10124 times.
✗ Branch 1 not taken.
10124 init_variable_default_paths();
8227
8228 int heo_error;
8229
8230 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
8231 /*
8232 Initialize the array of performance schema instrument configurations.
8233 */
8234
1/2
✓ Branch 0 taken 10124 times.
✗ Branch 1 not taken.
10124 init_pfs_instrument_array();
8235 #endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
8236
8237 /* init_error_log() is required by error_log_printf() in
8238 option_error_reporter() */
8239 // Init error log subsystem. This does not actually open the log yet.
8240
2/6
✓ Branch 0 taken 10124 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10124 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
10124 if (init_error_log()) unireg_abort(MYSQLD_ABORT_EXIT);
8241
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
10124 heo_error = handle_early_options();
8242
8243
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 opt_jemalloc_detected = jemalloc_detected();
8244
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 jemalloc_profiling_enable(opt_jemalloc_profiling_enabled);
8245
8246 9813 init_sql_statement_names();
8247 9813 ulong requested_open_files = 0;
8248
3/4
✓ Branch 0 taken 9808 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 9808 times.
✗ Branch 3 not taken.
9813 if (!opt_validate_config) adjust_related_options(&requested_open_files);
8249 // moved signal initialization here so that PFS thread inherited signal mask
8250
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 my_init_signals();
8251
8252 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
8253
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 if (heo_error == 0) {
8254
6/6
✓ Branch 0 taken 9794 times.
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 9582 times.
✓ Branch 3 taken 212 times.
✓ Branch 4 taken 9582 times.
✓ Branch 5 taken 231 times.
9813 if (!is_help_or_validate_option() && !opt_initialize) {
8255 int pfs_rc;
8256 /* Add sizing hints from the server sizing parameters. */
8257 9582 pfs_param.m_hints.m_table_definition_cache = table_def_size;
8258 9582 pfs_param.m_hints.m_table_open_cache = table_cache_size;
8259 9582 pfs_param.m_hints.m_max_connections = max_connections;
8260 9582 pfs_param.m_hints.m_open_files_limit = requested_open_files;
8261 9582 pfs_param.m_hints.m_max_prepared_stmt_count = max_prepared_stmt_count;
8262
8263
1/2
✓ Branch 0 taken 9582 times.
✗ Branch 1 not taken.
9582 pfs_rc = initialize_performance_schema(
8264 &pfs_param, &psi_thread_hook, &psi_mutex_hook, &psi_rwlock_hook,
8265 &psi_cond_hook, &psi_file_hook, &psi_socket_hook, &psi_table_hook,
8266 &psi_mdl_hook, &psi_idle_hook, &psi_stage_hook, &psi_statement_hook,
8267 &psi_transaction_hook, &psi_memory_hook, &psi_error_hook,
8268 &psi_data_lock_hook, &psi_system_hook, &psi_tls_channel_hook);
8269
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9582 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9582 if ((pfs_rc != 0) && pfs_param.m_enabled) {
8270 pfs_param.m_enabled = false;
8271 LogErr(WARNING_LEVEL, ER_PERFSCHEMA_INIT_FAILED);
8272 }
8273 }
8274 }
8275 #endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
8276
8277 #ifdef WITH_LOCK_ORDER
8278 if (heo_error == 0) {
8279 if (lo_param.m_enabled && !opt_help && !opt_initialize) {
8280 int lo_rc;
8281 lo_rc = LO_init(&lo_param, &psi_thread_hook, &psi_mutex_hook,
8282 &psi_rwlock_hook, &psi_cond_hook, &psi_file_hook,
8283 &psi_socket_hook, &psi_table_hook, &psi_mdl_hook,
8284 &psi_idle_hook, &psi_stage_hook, &psi_statement_hook,
8285 &psi_transaction_hook, &psi_memory_hook);
8286 if (lo_rc != 0) {
8287 LogErr(WARNING_LEVEL, ER_LOCK_ORDER_INIT_FAILED);
8288 }
8289 }
8290 }
8291 #endif /* WITH_LOCK_ORDER */
8292
8293 /*
8294 Other provider of the instrumentation interface should
8295 initialize PSI_hook here:
8296 - HAVE_PSI_INTERFACE is for the instrumentation interface
8297 - WITH_PERFSCHEMA_STORAGE_ENGINE is for one implementation
8298 of the interface,
8299 but there could be alternate implementations, which is why
8300 these two defines are kept separate.
8301 */
8302
8303 #ifdef HAVE_PSI_INTERFACE
8304 /*
8305 Obtain the current performance schema instrumentation interface,
8306 if available.
8307 */
8308
8309 void *service;
8310
8311
2/2
✓ Branch 0 taken 9575 times.
✓ Branch 1 taken 238 times.
9813 if (psi_thread_hook != nullptr) {
8312
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 service = psi_thread_hook->get_interface(PSI_CURRENT_THREAD_VERSION);
8313
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 if (service != nullptr) {
8314
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 set_psi_thread_service(service);
8315 }
8316 }
8317
8318
2/2
✓ Branch 0 taken 9575 times.
✓ Branch 1 taken 238 times.
9813 if (psi_mutex_hook != nullptr) {
8319
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 service = psi_mutex_hook->get_interface(PSI_CURRENT_MUTEX_VERSION);
8320
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 if (service != nullptr) {
8321
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 set_psi_mutex_service(service);
8322 }
8323 }
8324
8325
2/2
✓ Branch 0 taken 9575 times.
✓ Branch 1 taken 238 times.
9813 if (psi_rwlock_hook != nullptr) {
8326
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 service = psi_rwlock_hook->get_interface(PSI_CURRENT_RWLOCK_VERSION);
8327
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 if (service != nullptr) {
8328
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 set_psi_rwlock_service(service);
8329 }
8330 }
8331
8332
2/2
✓ Branch 0 taken 9575 times.
✓ Branch 1 taken 238 times.
9813 if (psi_cond_hook != nullptr) {
8333
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 service = psi_cond_hook->get_interface(PSI_CURRENT_COND_VERSION);
8334
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 if (service != nullptr) {
8335
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 set_psi_cond_service(service);
8336 }
8337 }
8338
8339
2/2
✓ Branch 0 taken 9575 times.
✓ Branch 1 taken 238 times.
9813 if (psi_file_hook != nullptr) {
8340
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 service = psi_file_hook->get_interface(PSI_CURRENT_FILE_VERSION);
8341
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 if (service != nullptr) {
8342
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 set_psi_file_service(service);
8343 }
8344 }
8345
8346
2/2
✓ Branch 0 taken 9575 times.
✓ Branch 1 taken 238 times.
9813 if (psi_socket_hook != nullptr) {
8347
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 service = psi_socket_hook->get_interface(PSI_CURRENT_SOCKET_VERSION);
8348
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 if (service != nullptr) {
8349
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 set_psi_socket_service(service);
8350 }
8351 }
8352
8353
2/2
✓ Branch 0 taken 9575 times.
✓ Branch 1 taken 238 times.
9813 if (psi_table_hook != nullptr) {
8354
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 service = psi_table_hook->get_interface(PSI_CURRENT_TABLE_VERSION);
8355
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 if (service != nullptr) {
8356
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 set_psi_table_service(service);
8357 }
8358 }
8359
8360
2/2
✓ Branch 0 taken 9575 times.
✓ Branch 1 taken 238 times.
9813 if (psi_mdl_hook != nullptr) {
8361
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 service = psi_mdl_hook->get_interface(PSI_CURRENT_MDL_VERSION);
8362
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 if (service != nullptr) {
8363
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 set_psi_mdl_service(service);
8364 }
8365 }
8366
8367
2/2
✓ Branch 0 taken 9575 times.
✓ Branch 1 taken 238 times.
9813 if (psi_idle_hook != nullptr) {
8368
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 service = psi_idle_hook->get_interface(PSI_CURRENT_IDLE_VERSION);
8369
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 if (service != nullptr) {
8370
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 set_psi_idle_service(service);
8371 }
8372 }
8373
8374
2/2
✓ Branch 0 taken 9575 times.
✓ Branch 1 taken 238 times.
9813 if (psi_stage_hook != nullptr) {
8375
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 service = psi_stage_hook->get_interface(PSI_CURRENT_STAGE_VERSION);
8376
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 if (service != nullptr) {
8377
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 set_psi_stage_service(service);
8378 }
8379 }
8380
8381
2/2
✓ Branch 0 taken 9575 times.
✓ Branch 1 taken 238 times.
9813 if (psi_statement_hook != nullptr) {
8382
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 service = psi_statement_hook->get_interface(PSI_CURRENT_STATEMENT_VERSION);
8383
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 if (service != nullptr) {
8384
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 set_psi_statement_service(service);
8385 }
8386 }
8387
8388
2/2
✓ Branch 0 taken 9575 times.
✓ Branch 1 taken 238 times.
9813 if (psi_transaction_hook != nullptr) {
8389 service =
8390
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 psi_transaction_hook->get_interface(PSI_CURRENT_TRANSACTION_VERSION);
8391
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 if (service != nullptr) {
8392
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 set_psi_transaction_service(service);
8393 }
8394 }
8395
8396
2/2
✓ Branch 0 taken 9575 times.
✓ Branch 1 taken 238 times.
9813 if (psi_memory_hook != nullptr) {
8397
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 service = psi_memory_hook->get_interface(PSI_CURRENT_MEMORY_VERSION);
8398
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 if (service != nullptr) {
8399
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 set_psi_memory_service(service);
8400 }
8401 }
8402
8403
2/2
✓ Branch 0 taken 9575 times.
✓ Branch 1 taken 238 times.
9813 if (psi_error_hook != nullptr) {
8404
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 service = psi_error_hook->get_interface(PSI_CURRENT_ERROR_VERSION);
8405
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 if (service != nullptr) {
8406
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 set_psi_error_service(service);
8407 }
8408 }
8409
8410
2/2
✓ Branch 0 taken 9575 times.
✓ Branch 1 taken 238 times.
9813 if (psi_data_lock_hook != nullptr) {
8411
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 service = psi_data_lock_hook->get_interface(PSI_CURRENT_DATA_LOCK_VERSION);
8412
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 if (service != nullptr) {
8413
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 set_psi_data_lock_service(service);
8414 }
8415 }
8416
8417
2/2
✓ Branch 0 taken 9575 times.
✓ Branch 1 taken 238 times.
9813 if (psi_system_hook != nullptr) {
8418
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 service = psi_system_hook->get_interface(PSI_CURRENT_SYSTEM_VERSION);
8419
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 if (service != nullptr) {
8420
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 set_psi_system_service(service);
8421 }
8422 }
8423
8424
2/2
✓ Branch 0 taken 9575 times.
✓ Branch 1 taken 238 times.
9813 if (psi_tls_channel_hook != nullptr) {
8425 service =
8426
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 psi_tls_channel_hook->get_interface(PSI_CURRENT_TLS_CHANNEL_VERSION);
8427
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 if (service != nullptr) {
8428
1/2
✓ Branch 0 taken 9575 times.
✗ Branch 1 not taken.
9575 set_psi_tls_channel_service(service);
8429 }
8430 }
8431
8432 /*
8433 Now that we have parsed the command line arguments, and have initialized
8434 the performance schema itself, the next step is to register all the
8435 server instruments.
8436 */
8437
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 init_server_psi_keys();
8438
8439 /*
8440 Now that some instrumentation is in place,
8441 recreate objects which were initialised early,
8442 so that they are instrumented as well.
8443 */
8444
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 my_thread_global_reinit();
8445 #endif /* HAVE_PSI_INTERFACE */
8446
8447 /* This limits ability to configure SSL library through config options */
8448
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 init_ssl();
8449
8450 /* Set umask as early as possible */
8451 9813 umask(((~my_umask) & 0666));
8452
8453 /*
8454 Initialize Components core subsystem early on, once we have PSI, which it
8455 uses. This part doesn't use any more MySQL-specific functionalities but
8456 error logging and PFS.
8457 */
8458
2/4
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9813 times.
9813 if (component_infrastructure_init()) {
8459 flush_error_log_messages();
8460 return 1;
8461 }
8462
8463 {
8464 /* Must be initialized early because it is required by dynamic loader */
8465 9813 files_charset_info = &my_charset_utf8_general_ci;
8466 auto keyring_helper = std::make_unique<Plugin_and_data_dir_option_parser>(
8467
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 remaining_argc, remaining_argv);
8468
8469
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9813 times.
9813 if (keyring_helper->valid() == false) {
8470 flush_error_log_messages();
8471 return 1;
8472 }
8473
8474
2/4
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9813 times.
9813 if (initialize_manifest_file_components()) {
8475 flush_error_log_messages();
8476 return 1;
8477 }
8478
8479 /*
8480 If keyring component was loaded through manifest file, services provided
8481 by such a component should get priority over keyring plugin. That's why
8482 we have to set defaults before proxy keyring services are loaded.
8483 */
8484
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 set_srv_keyring_implementation_as_default();
8485
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 }
8486
8487 /*
8488 Append read only persisted variables to command line now.
8489 Note that if arg separator is already added, it will not
8490 be added again.
8491 */
8492
2/4
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9813 times.
9813 if (persisted_variables_cache.append_read_only_variables(
8493 &remaining_argc, &remaining_argv, arg_separator_added, false)) {
8494 flush_error_log_messages();
8495 return 1;
8496 }
8497 9813 my_getopt_use_args_separator = false;
8498
8499 /*
8500 Initialize Performance Schema component services.
8501 */
8502 #ifdef HAVE_PSI_THREAD_INTERFACE
8503
6/6
✓ Branch 0 taken 9794 times.
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 9582 times.
✓ Branch 3 taken 212 times.
✓ Branch 4 taken 9582 times.
✓ Branch 5 taken 231 times.
9813 if (!is_help_or_validate_option() && !opt_initialize) {
8504
1/2
✓ Branch 0 taken 9582 times.
✗ Branch 1 not taken.
9582 register_pfs_notification_service();
8505
1/2
✓ Branch 0 taken 9582 times.
✗ Branch 1 not taken.
9582 register_pfs_resource_group_service();
8506 }
8507 #endif
8508
8509 // Initialize the resource group subsystem.
8510
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 auto res_grp_mgr = resourcegroups::Resource_group_mgr::instance();
8511
6/6
✓ Branch 0 taken 9794 times.
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 9582 times.
✓ Branch 3 taken 212 times.
✓ Branch 4 taken 9582 times.
✓ Branch 5 taken 231 times.
9813 if (!is_help_or_validate_option() && !opt_initialize) {
8512
2/4
✓ Branch 0 taken 9582 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9582 times.
9582 if (res_grp_mgr->init()) {
8513 LogErr(ERROR_LEVEL, ER_RESOURCE_GROUP_SUBSYSTEM_INIT_FAILED);
8514 unireg_abort(MYSQLD_ABORT_EXIT);
8515 }
8516 }
8517
8518 #ifdef HAVE_PSI_THREAD_INTERFACE
8519 /* Instrument the main thread */
8520
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 PSI_thread *psi = PSI_THREAD_CALL(new_thread)(key_thread_main, 0, nullptr, 0);
8521
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 PSI_THREAD_CALL(set_thread_os_id)(psi);
8522
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 PSI_THREAD_CALL(set_thread)(psi);
8523 #endif /* HAVE_PSI_THREAD_INTERFACE */
8524
8525 /* Initialize audit interface globals. Audit plugins are inited later. */
8526
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 mysql_audit_initialize();
8527
8528
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 Srv_session::module_init();
8529
8530 /*
8531 Perform basic query log initialization. Should be called after
8532 MY_INIT, as it initializes mutexes.
8533 */
8534
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 query_logger.init();
8535
8536
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9813 times.
9813 if (heo_error) {
8537 /*
8538 Parsing command line option failed,
8539 Since we don't have a workable remaining_argc/remaining_argv
8540 to continue the server initialization, this is as far as this
8541 code can go.
8542 This is the best effort to log meaningful messages:
8543 - messages will be printed to stderr, which is not redirected yet,
8544 - messages will be printed in the NT event log, for windows.
8545 */
8546 flush_error_log_messages();
8547 /*
8548 Not enough initializations for unireg_abort()
8549 Using exit() for windows.
8550 */
8551 exit(MYSQLD_ABORT_EXIT);
8552 }
8553
8554
3/4
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 43 times.
✓ Branch 3 taken 9770 times.
9813 if (init_common_variables()) {
8555
1/2
✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
43 setup_error_log();
8556
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
43 unireg_abort(MYSQLD_ABORT_EXIT); // Will do exit
8557 }
8558
8559
1/2
✓ Branch 0 taken 9770 times.
✗ Branch 1 not taken.
9770 keyring_lockable_init();
8560
8561 /*
8562 Install server's my_abort routine to assure my_aborts prints signal info
8563 sequentially without sudden termination.
8564 */
8565
1/2
✓ Branch 0 taken 9770 times.
✗ Branch 1 not taken.
9770 set_my_abort(my_server_abort);
8566
8567 9770 size_t guardize = 0;
8568 #ifndef _WIN32
8569 9770 int retval = pthread_attr_getguardsize(&connection_attrib, &guardize);
8570
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9770 times.
9770 assert(retval == 0);
8571
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9770 times.
9770 if (retval != 0) guardize = my_thread_stack_size;
8572 #endif
8573
8574 #if defined(__ia64__) || defined(__ia64)
8575 /*
8576 Peculiar things with ia64 platforms - it seems we only have half the
8577 stack size in reality, so we have to double it here
8578 */
8579 guardize = my_thread_stack_size;
8580 #endif
8581
8582
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9770 times.
9770 if (0 != my_thread_attr_setstacksize(&connection_attrib,
8583 my_thread_stack_size + guardize)) {
8584 assert(false);
8585 }
8586
8587 {
8588 /* Retrieve used stack size; Needed for checking stack overflows */
8589 9770 size_t stack_size = 0;
8590 9770 my_thread_attr_getstacksize(&connection_attrib, &stack_size);
8591
8592 /* We must check if stack_size = 0 as Solaris 2.9 can return 0 here */
8593
2/4
✓ Branch 0 taken 9770 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9770 times.
9770 if (stack_size && stack_size < (my_thread_stack_size + guardize)) {
8594 LogErr(WARNING_LEVEL, ER_STACKSIZE_UNEXPECTED,
8595 my_thread_stack_size + guardize, (long)stack_size);
8596 #if defined(__ia64__) || defined(__ia64)
8597 my_thread_stack_size = stack_size / 2;
8598 #else
8599 my_thread_stack_size = static_cast<ulong>(stack_size - guardize);
8600 #endif
8601 }
8602 }
8603
8604 #ifndef NDEBUG
8605
1/2
✓ Branch 0 taken 9770 times.
✗ Branch 1 not taken.
9770 test_lc_time_sz();
8606 9770 srand(static_cast<uint>(time(nullptr)));
8607 #endif
8608
8609 #if !defined(_WIN32)
8610
8611
3/4
✓ Branch 0 taken 211 times.
✓ Branch 1 taken 9559 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 211 times.
9770 if (opt_initialize && opt_daemonize) {
8612 fprintf(stderr, "Initialize and daemon options are incompatible.\n");
8613 unireg_abort(MYSQLD_ABORT_EXIT);
8614 }
8615
8616
6/8
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 9764 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 9770 times.
9774 if (opt_daemonize && log_error_dest == disabled_my_option &&
8617
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
4 (isatty(STDOUT_FILENO) || isatty(STDERR_FILENO))) {
8618 // Just use the default in this case.
8619 log_error_dest = "";
8620 }
8621
8622
3/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 9764 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
9770 if (opt_daemonize && !opt_validate_config) {
8623
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (chdir("/") < 0) {
8624 LogErr(ERROR_LEVEL, ER_CANNOT_CHANGE_TO_ROOT_DIR, strerror(errno));
8625 unireg_abort(MYSQLD_ABORT_EXIT);
8626 }
8627
8628
3/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 5 times.
6 if ((pipe_write_fd = mysqld::runtime::mysqld_daemonize()) < -1) {
8629
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(ERROR_LEVEL, ER_FAILED_START_MYSQLD_DAEMON);
8630
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
1 unireg_abort(MYSQLD_ABORT_EXIT);
8631 }
8632
8633
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
5 if (pipe_write_fd < 0) {
8634 // This is the launching process and the daemon appears to have
8635 // started ok (Need to call unireg_abort with success here to
8636 // clean up resources in the launching process.
8637
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
2 unireg_abort(MYSQLD_SUCCESS_EXIT);
8638 }
8639
8640 // Need to update the value of current_pid so that it reflects the
8641 // pid of the daemon (the previous value was set by unireg_init()
8642 // while still in the launcher process.
8643 3 current_pid = static_cast<ulong>(getpid());
8644 }
8645 #endif
8646
8647 #ifndef _WIN32
8648
1/2
✓ Branch 0 taken 9767 times.
✗ Branch 1 not taken.
9767 user_info = check_user(mysqld_user);
8649
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9767 times.
9767 if (!user_info.IsVoid()) {
8650 #if HAVE_CHOWN
8651 if (unlikely(opt_initialize)) {
8652 /* need to change the owner of the freshly created data directory */
8653 MY_STAT stat;
8654 char errbuf[MYSYS_STRERROR_SIZE];
8655 bool must_chown = true;
8656
8657 /* fetch the directory's owner */
8658 if (!my_stat(mysql_real_data_home, &stat, MYF(0))) {
8659 LogErr(INFORMATION_LEVEL, ER_CANT_STAT_DATADIR, my_errno(),
8660 my_strerror(errbuf, sizeof(errbuf), my_errno()));
8661 }
8662 /* Don't change it if it's already the same as SElinux stops this */
8663 else if (stat.st_uid == user_info.pw_uid &&
8664 stat.st_gid == user_info.pw_gid)
8665 must_chown = false;
8666
8667 if (must_chown &&
8668 chown(mysql_real_data_home, user_info.pw_uid, user_info.pw_gid)) {
8669 LogErr(ERROR_LEVEL, ER_CANT_CHOWN_DATADIR, mysqld_user);
8670 unireg_abort(1);
8671 }
8672 }
8673 #endif
8674
8675 #if defined(HAVE_MLOCKALL) && defined(MCL_CURRENT)
8676 if (locked_in_memory) // getuid() == 0 here
8677 set_effective_user(user_info);
8678 else
8679 #endif
8680 set_user(mysqld_user, user_info);
8681 }
8682 #endif // !_WIN32
8683
8684 /*
8685 initiate key migration if any one of the migration specific
8686 options are provided.
8687 */
8688
4/6
✓ Branch 0 taken 9762 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 9762 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9762 times.
9767 if (opt_keyring_migration_source || opt_keyring_migration_destination ||
8689 migrate_connect_options) {
8690 5 int exit_state = MYSQLD_ABORT_EXIT;
8691 while (true) {
8692
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 Migrate_keyring mk;
8693 5 my_getopt_skip_unknown = true;
8694
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
5 if (mk.init(remaining_argc, remaining_argv, opt_keyring_migration_source,
8695 opt_keyring_migration_destination, opt_keyring_migration_user,
8696 opt_keyring_migration_host, opt_keyring_migration_password,
8697 opt_keyring_migration_socket, opt_keyring_migration_port,
8698 opt_keyring_migration_to_component)) {
8699 LogErr(ERROR_LEVEL, ER_KEYRING_MIGRATION_FAILED);
8700 log_error_dest = "stderr";
8701 flush_error_log_messages();
8702 break;
8703 }
8704
8705
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
5 if (mk.execute()) {
8706 LogErr(ERROR_LEVEL, ER_KEYRING_MIGRATION_FAILED);
8707 log_error_dest = "stderr";
8708 flush_error_log_messages();
8709 break;
8710 }
8711
8712 5 my_getopt_skip_unknown = false;
8713
8/16
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 5 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 5 times.
✗ Branch 15 not taken.
5 LogErr(INFORMATION_LEVEL, ER_KEYRING_MIGRATION_SUCCESSFUL);
8714 5 log_error_dest = "stderr";
8715
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 flush_error_log_messages();
8716 5 exit_state = MYSQLD_SUCCESS_EXIT;
8717 5 break;
8718 5 }
8719
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
5 unireg_abort(exit_state);
8720 }
8721
8722 /*
8723 We have enough space for fiddling with the argv, continue
8724 */
8725
4/4
✓ Branch 0 taken 9744 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 9759 times.
19506 if (!(is_help_or_validate_option()) &&
8726
3/4
✓ Branch 0 taken 9744 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 9741 times.
9744 my_setwd(mysql_real_data_home, MYF(0))) {
8727 char errbuf[MYSYS_STRERROR_SIZE];
8728
8729
9/18
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 3 times.
✗ Branch 17 not taken.
3 LogErr(ERROR_LEVEL, ER_CANT_SET_DATA_DIR, mysql_real_data_home, errno,
8730 my_strerror(errbuf, sizeof(errbuf), errno));
8731
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
3 unireg_abort(MYSQLD_ABORT_EXIT); /* purecov: inspected */
8732 }
8733
8734 #ifdef WITH_WSREP
8735 // Initialize wsrep_provider_set before anything else wsrep related
8736 9759 wsrep_provider_set =
8737
3/4
✓ Branch 0 taken 9759 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 456 times.
✓ Branch 3 taken 9303 times.
9759 wsrep_provider != nullptr && strcmp(wsrep_provider, WSREP_NONE) != 0;
8738 #endif
8739
8740 /*
8741 The subsequent calls may take a long time : e.g. innodb log read.
8742 Thus set the long running service control manager timeout
8743 */
8744 #if defined(_WIN32)
8745 if (windows_service) {
8746 if (setup_service_status_cmd_processed_handle())
8747 unireg_abort(MYSQLD_ABORT_EXIT);
8748
8749 char buf[32];
8750 snprintf(buf, sizeof(buf), "T %lu", slow_start_timeout);
8751 Service_status_msg msg(buf);
8752 send_service_status(msg);
8753 }
8754 #endif
8755
8756 /* Determine default TCP port and unix socket name */
8757
1/2
✓ Branch 0 taken 9759 times.
✗ Branch 1 not taken.
9759 set_ports();
8758
8759
2/6
✓ Branch 0 taken 9472 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9472 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
9759 if (init_server_components()) unireg_abort(MYSQLD_ABORT_EXIT);
8760
8761 #ifdef WITH_WSREP /* WSREP AFTER SE */
8762
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 9456 times.
9472 if (wsrep_recovery) {
8763
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 wsrep_recover();
8764
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
16 unireg_abort(0);
8765 }
8766 #endif /* WITH_WSREP */
8767
8768
2/2
✓ Branch 0 taken 220 times.
✓ Branch 1 taken 9236 times.
9456 if (!server_id_supplied)
8769
8/16
✓ Branch 0 taken 220 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 220 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 220 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 220 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 220 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 220 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 220 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 220 times.
✗ Branch 15 not taken.
220 LogErr(INFORMATION_LEVEL, ER_WARN_NO_SERVERID_SPECIFIED);
8770
8771 /* Server generates uuid after innodb is initialized. But during
8772 initialization, if tablespaces like system, redo, temporary are encrypted,
8773 they are initialized with "empty" UUID. Now UUID is available, fix the
8774 empty UUID of such tablespaces now */
8775
1/2
✓ Branch 0 taken 9456 times.
✗ Branch 1 not taken.
9456 if (innodb_hton != nullptr) {
8776
2/4
✓ Branch 0 taken 9456 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9456 times.
18912 if (innodb_hton->fix_tablespaces_empty_uuid != nullptr &&
8777
2/4
✓ Branch 0 taken 9456 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9456 times.
9456 innodb_hton->fix_tablespaces_empty_uuid()) {
8778 sql_print_error(
8779 "Fixing empty UUID with InnoDB Engine failed. Please"
8780 " check if keyring plugin is loaded and execute"
8781 " \"ALTER INSTANCE ROTATE INNODB MASTER KEY\"");
8782 }
8783 // Only now, that we have server_uuid initialized we can
8784 // instruct encryption threads to do some work
8785
1/2
✓ Branch 0 taken 9456 times.
✗ Branch 1 not taken.
9456 if (innodb_hton->fix_default_table_encryption != nullptr) {
8786
1/2
✓ Branch 0 taken 9456 times.
✗ Branch 1 not taken.
9456 innodb_hton->fix_default_table_encryption(
8787 global_system_variables.default_table_encryption, true);
8788 }
8789 }
8790
8791 /*
8792 Add server_uuid to the sid_map. This must be done after
8793 server_uuid has been initialized in init_server_auto_options and
8794 after the binary log (and sid_map file) has been initialized in
8795 init_server_components().
8796
8797 No error message is needed: init_sid_map() prints a message.
8798
8799 Strictly speaking, this is not currently needed when
8800 opt_bin_log==0, since the variables that gtid_state->init
8801 initializes are not currently used in that case. But we call it
8802 regardless to avoid possible future bugs if gtid_state ever
8803 needs to do anything else.
8804 */
8805
1/2
✓ Branch 0 taken 9456 times.
✗ Branch 1 not taken.
9456 global_sid_lock->wrlock();
8806
1/2
✓ Branch 0 taken 9456 times.
✗ Branch 1 not taken.
9456 int gtid_ret = gtid_state->init();
8807
1/2
✓ Branch 0 taken 9456 times.
✗ Branch 1 not taken.
9456 global_sid_lock->unlock();
8808
8809
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9456 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9456 if (gtid_ret) unireg_abort(MYSQLD_ABORT_EXIT);
8810
8811
3/4
✓ Branch 0 taken 9254 times.
✓ Branch 1 taken 202 times.
✓ Branch 2 taken 9254 times.
✗ Branch 3 not taken.
9456 if (!opt_initialize && !opt_initialize_insecure) {
8812 // Initialize executed_gtids from mysql.gtid_executed table.
8813
2/6
✓ Branch 0 taken 9254 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9254 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
9254 if (gtid_state->read_gtid_executed_from_table() == -1) unireg_abort(1);
8814 }
8815
8816
2/2
✓ Branch 0 taken 8991 times.
✓ Branch 1 taken 465 times.
9456 if (opt_bin_log) {
8817 /*
8818 Initialize GLOBAL.GTID_EXECUTED and GLOBAL.GTID_PURGED from
8819 gtid_executed table and binlog files during server startup.
8820 */
8821 Gtid_set *executed_gtids =
8822 8991 const_cast<Gtid_set *>(gtid_state->get_executed_gtids());
8823 8991 Gtid_set *lost_gtids = const_cast<Gtid_set *>(gtid_state->get_lost_gtids());
8824 Gtid_set *gtids_only_in_table =
8825 8991 const_cast<Gtid_set *>(gtid_state->get_gtids_only_in_table());
8826 Gtid_set *previous_gtids_logged =
8827 8991 const_cast<Gtid_set *>(gtid_state->get_previous_gtids_logged());
8828
8829
1/2
✓ Branch 0 taken 8991 times.
✗ Branch 1 not taken.
8991 Gtid_set purged_gtids_from_binlog(global_sid_map, global_sid_lock);
8830
1/2
✓ Branch 0 taken 8991 times.
✗ Branch 1 not taken.
8991 Gtid_set gtids_in_binlog(global_sid_map, global_sid_lock);
8831
1/2
✓ Branch 0 taken 8991 times.
✗ Branch 1 not taken.
8991 Gtid_set gtids_in_binlog_not_in_table(global_sid_map, global_sid_lock);
8832
8833
2/4
✓ Branch 0 taken 8991 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8991 times.
8991 if (mysql_bin_log.init_gtid_sets(
8834 &gtids_in_binlog, &purged_gtids_from_binlog,
8835 opt_source_verify_checksum, true /*true=need lock*/,
8836 nullptr /*trx_parser*/, nullptr /*partial_trx*/,
8837 true /*is_server_starting*/))
8838 unireg_abort(MYSQLD_ABORT_EXIT);
8839
8840
1/2
✓ Branch 0 taken 8991 times.
✗ Branch 1 not taken.
8991 global_sid_lock->wrlock();
8841
8842
1/2
✓ Branch 0 taken 8991 times.
✗ Branch 1 not taken.
8991 purged_gtids_from_binlog.dbug_print("purged_gtids_from_binlog");
8843
1/2
✓ Branch 0 taken 8991 times.
✗ Branch 1 not taken.
8991 gtids_in_binlog.dbug_print("gtids_in_binlog");
8844
8845
5/6
✓ Branch 0 taken 8991 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 441 times.
✓ Branch 3 taken 8550 times.
✓ Branch 4 taken 78 times.
✓ Branch 5 taken 8913 times.
9432 if (!gtids_in_binlog.is_empty() &&
8846
3/4
✓ Branch 0 taken 441 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 78 times.
✓ Branch 3 taken 363 times.
441 !gtids_in_binlog.is_subset(executed_gtids)) {
8847
1/2
✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
78 gtids_in_binlog_not_in_table.add_gtid_set(&gtids_in_binlog);
8848
3/4
✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 64 times.
✓ Branch 3 taken 14 times.
78 if (!executed_gtids->is_empty())
8849
1/2
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
64 gtids_in_binlog_not_in_table.remove_gtid_set(executed_gtids);
8850 /*
8851 Save unsaved GTIDs into gtid_executed table, in the following
8852 four cases:
8853 1. the upgrade case.
8854 2. the case that a slave is provisioned from a backup of
8855 the master and the slave is cleaned by RESET MASTER
8856 and RESET SLAVE before this.
8857 3. the case that no binlog rotation happened from the
8858 last RESET MASTER on the server before it crashes.
8859 4. The set of GTIDs of the last binlog is not saved into the
8860 gtid_executed table if server crashes, so we save it into
8861 gtid_executed table and executed_gtids during recovery
8862 from the crash.
8863 */
8864
2/4
✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 78 times.
78 if (gtid_state->save(&gtids_in_binlog_not_in_table) == -1) {
8865 global_sid_lock->unlock();
8866 unireg_abort(MYSQLD_ABORT_EXIT);
8867 }
8868
1/2
✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
78 executed_gtids->add_gtid_set(&gtids_in_binlog_not_in_table);
8869 }
8870
8871 /* gtids_only_in_table= executed_gtids - gtids_in_binlog */
8872
2/4
✓ Branch 0 taken 8991 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8991 times.
8991 if (gtids_only_in_table->add_gtid_set(executed_gtids) != RETURN_STATUS_OK) {
8873 global_sid_lock->unlock();
8874 unireg_abort(MYSQLD_ABORT_EXIT);
8875 }
8876
1/2
✓ Branch 0 taken 8991 times.
✗ Branch 1 not taken.
8991 gtids_only_in_table->remove_gtid_set(&gtids_in_binlog);
8877 /*
8878 lost_gtids = executed_gtids -
8879 (gtids_in_binlog - purged_gtids_from_binlog)
8880 = gtids_only_in_table + purged_gtids_from_binlog;
8881 */
8882
2/4
✓ Branch 0 taken 8991 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8991 times.
8991 assert(lost_gtids->is_empty());
8883
3/6
✓ Branch 0 taken 8991 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8991 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 8991 times.
17982 if (lost_gtids->add_gtid_set(gtids_only_in_table) != RETURN_STATUS_OK ||
8884
2/4
✓ Branch 0 taken 8991 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8991 times.
8991 lost_gtids->add_gtid_set(&purged_gtids_from_binlog) !=
8885 RETURN_STATUS_OK) {
8886 global_sid_lock->unlock();
8887 unireg_abort(MYSQLD_ABORT_EXIT);
8888 }
8889
8890 /* Prepare previous_gtids_logged for next binlog */
8891
2/4
✓ Branch 0 taken 8991 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8991 times.
8991 if (previous_gtids_logged->add_gtid_set(&gtids_in_binlog) !=
8892 RETURN_STATUS_OK) {
8893 global_sid_lock->unlock();
8894 unireg_abort(MYSQLD_ABORT_EXIT);
8895 }
8896
8897 /*
8898 Write the previous set of gtids at this point because during
8899 the creation of the binary log this is not done as we cannot
8900 move the init_gtid_sets() to a place before opening the binary
8901 log. This requires some investigation.
8902
8903 /Alfranio
8904 */
8905
1/2
✓ Branch 0 taken 8991 times.
✗ Branch 1 not taken.
8991 Previous_gtids_log_event prev_gtids_ev(&gtids_in_binlog);
8906
8907
1/2
✓ Branch 0 taken 8991 times.
✗ Branch 1 not taken.
8991 global_sid_lock->unlock();
8908
8909 8991 (prev_gtids_ev.common_footer)->checksum_alg =
8910 8991 static_cast<enum_binlog_checksum_alg>(binlog_checksum_options);
8911
8912
2/4
✓ Branch 0 taken 8991 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8991 times.
8991 if (mysql_bin_log.write_event_to_binlog_and_sync(&prev_gtids_ev))
8913 unireg_abort(MYSQLD_ABORT_EXIT);
8914
8915 #ifdef WITH_WSREP
8916 /* In wsrep_recovery mode, PXC avoid creation of new binlog file for
8917 the reason mentioned above. In light of the said flow avoid purge
8918 action on binlog.
8919
8920 Don't spawn a new binlog file during wsrep-recovery. Why ?
8921 - Recovery flow is only going to read existing wsrep saved co-ordinate
8922 from sys_header. No other action is performed that needs binlogging.
8923
8924 - Existing server flow looks at last binlog to set gtid_executed if server
8925 was shutdown abruptly. Newly create binlog will not have any such
8926 information and so restart post wsrep_recover will result in gtid_executed
8927 to be empty. */
8928
1/2
✓ Branch 0 taken 8991 times.
✗ Branch 1 not taken.
8991 if (!wsrep_recovery) {
8929 #endif /* WITH_WSREP */
8930 // run auto purge member function. It will evaluate auto purge controls
8931 // and configuration, calculate which log files are to be purged, and
8932 // if any file is to be purged, it will purge it. This is all encapsulated
8933 // insiude the auto purge member function.
8934 //
8935 // Note on the DBUG_EVALUATE_IF usage below:
8936 // - when compiling it out: the condition evaluates to true, thus
8937 // mysql_bin_log.auto_purge_at_server_startup() runs
8938 // - when "expire_logs_always_at_start" is set: evaluates to false,
8939 // thus mysql_bin_log.purge_logs_before_date() runs
8940 // - when "expire_logs_always_at_start" is not set: evaluates to true,
8941 // this mysql_bin_log.auto_purge_at_server_startup() runs
8942
2/4
✓ Branch 0 taken 8991 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8991 times.
✗ Branch 3 not taken.
8991 if (DBUG_EVALUATE_IF("expire_logs_always_at_start", false, true))
8943
1/2
✓ Branch 0 taken 8991 times.
✗ Branch 1 not taken.
8991 mysql_bin_log.auto_purge_at_server_startup();
8944 else if (expire_logs_days > 0 || binlog_expire_logs_seconds > 0)
8945 mysql_bin_log.purge_logs_before_date(time(nullptr), true);
8946
8947
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 8987 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
8991 if (binlog_space_limit) mysql_bin_log.purge_logs_by_size(true);
8948
8949 #ifdef WITH_WSREP
8950 }
8951 #endif /* WITH_WSREP */
8952
4/6
✓ Branch 0 taken 8991 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1503 times.
✓ Branch 3 taken 7488 times.
✓ Branch 4 taken 1503 times.
✗ Branch 5 not taken.
8991 (void)RUN_HOOK(server_state, after_engine_recovery, (nullptr));
8953 8991 }
8954
8955
3/6
✓ Branch 0 taken 9455 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 9445 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
9456 if (init_ssl_communication()) unireg_abort(MYSQLD_ABORT_EXIT);
8956
3/6
✓ Branch 0 taken 9435 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 9420 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
9445 if (network_init()) unireg_abort(MYSQLD_ABORT_EXIT);
8957
8958 #ifdef _WIN32
8959 if (opt_require_secure_transport && !opt_enable_shared_memory &&
8960 !have_ssl() && !opt_initialize) {
8961 LogErr(ERROR_LEVEL, ER_TRANSPORTS_WHAT_TRANSPORTS);
8962 unireg_abort(MYSQLD_ABORT_EXIT);
8963 }
8964 #endif
8965
8966 /*
8967 Initialize my_str_malloc(), my_str_realloc() and my_str_free()
8968 */
8969 9420 my_str_malloc = &my_str_malloc_mysqld;
8970 9420 my_str_free = &my_str_free_mysqld;
8971 9420 my_str_realloc = &my_str_realloc_mysqld;
8972
8973 9420 error_handler_hook = my_message_sql;
8974
8975 9420 bool abort = false;
8976
8977 /* Save pid of this process in a file */
8978
2/2
✓ Branch 0 taken 9218 times.
✓ Branch 1 taken 202 times.
9420 if (!opt_initialize) {
8979
2/4
✓ Branch 0 taken 9218 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9218 times.
9218 if (create_pid_file()) abort = true;
8980 }
8981
8982 /* Read the optimizer cost model configuration tables */
8983
3/4
✓ Branch 0 taken 9218 times.
✓ Branch 1 taken 202 times.
✓ Branch 2 taken 9215 times.
✗ Branch 3 not taken.
9420 if (!opt_initialize) reload_optimizer_cost_constants();
8984
8985 9417 if (
8986 /*
8987 Read components table to restore previously installed components. This
8988 requires read access to mysql.component table.
8989 */
8990
5/8
✓ Branch 0 taken 9215 times.
✓ Branch 1 taken 202 times.
✓ Branch 2 taken 9215 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9215 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 9417 times.
18834 (!opt_initialize && mysql_component_infrastructure_init()) ||
8991
2/4
✓ Branch 0 taken 9417 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9417 times.
9417 mysql_rm_tmp_tables()) {
8992 abort = true;
8993 }
8994
8995 /* we do want to exit if there are any other unknown options */
8996
1/2
✓ Branch 0 taken 9417 times.
✗ Branch 1 not taken.
9417 if (remaining_argc > 1) {
8997 int ho_error;
8998 9417 struct my_option no_opts[] = {{nullptr, 0, nullptr, nullptr, nullptr,
8999 nullptr, GET_NO_ARG, NO_ARG, 0, 0, 0,
9000 nullptr, 0, nullptr}};
9001 /*
9002 We need to eat any 'loose' arguments first before we conclude
9003 that there are unprocessed options.
9004 */
9005 9417 my_getopt_skip_unknown = false;
9006
9007
3/4
✓ Branch 0 taken 9417 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
✓ Branch 3 taken 9385 times.
9417 if ((ho_error = handle_options(&remaining_argc, &remaining_argv, no_opts,
9008 mysqld_get_one_option)))
9009 32 abort = true;
9010 else {
9011 /* Add back the program name handle_options removes */
9012 9385 remaining_argc++;
9013 9385 remaining_argv--;
9014 9385 my_getopt_skip_unknown = true;
9015
9016
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 9382 times.
9385 if (remaining_argc > 1) {
9017
8/16
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
3 LogErr(ERROR_LEVEL, ER_EXCESS_ARGUMENTS, remaining_argv[1]);
9018
8/16
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
3 LogErr(INFORMATION_LEVEL, ER_VERBOSE_HINT);
9019 3 abort = true;
9020 }
9021 }
9022 }
9023
9024
7/8
✓ Branch 0 taken 9382 times.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 9380 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 9379 times.
✓ Branch 6 taken 36 times.
✓ Branch 7 taken 9379 times.
9417 if (abort || acl_init(opt_noacl)) {
9025
10/18
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
36 if (!abort) LogErr(ERROR_LEVEL, ER_PRIVILEGE_SYSTEM_INIT_FAILED);
9026 36 abort = true;
9027 36 opt_noacl = true;
9028 }
9029
9030 /*
9031 if running with --initialize, explicitly allocate the memory
9032 to be used by ACL objects.
9033 */
9034
3/4
✓ Branch 0 taken 202 times.
✓ Branch 1 taken 9213 times.
✓ Branch 2 taken 202 times.
✗ Branch 3 not taken.
9415 if (opt_initialize) init_acl_memory();
9035
9036
6/8
✓ Branch 0 taken 9379 times.
✓ Branch 1 taken 36 times.
✓ Branch 2 taken 9379 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9379 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 36 times.
✓ Branch 7 taken 9379 times.
18794 if (abort || my_tz_init((THD *)nullptr, default_tz_name, opt_initialize) ||
9037
2/4
✓ Branch 0 taken 9379 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9379 times.
9379 grant_init(opt_noacl)) {
9038 36 set_connection_events_loop_aborted(true);
9039
9040
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 delete_pid_file(MYF(MY_WME));
9041
9042
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
36 unireg_abort(MYSQLD_ABORT_EXIT);
9043 }
9044
9045 /*
9046 Bootstrap the dynamic privilege service implementation
9047 */
9048
2/4
✓ Branch 0 taken 9379 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9379 times.
9379 if (dynamic_privilege_init()) {
9049 LogErr(WARNING_LEVEL, ER_PERSISTENT_PRIVILEGES_BOOTSTRAP);
9050 }
9051
9052 /*
9053 In the case of upgrade, the bootstrap thread would have already initialized
9054 the structures necessary for federated server from mysql.servers table.
9055 Hence we need not initialize them again here.
9056 */
9057
7/8
✓ Branch 0 taken 9181 times.
✓ Branch 1 taken 198 times.
✓ Branch 2 taken 9181 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 177 times.
✓ Branch 5 taken 9004 times.
✓ Branch 6 taken 9007 times.
✓ Branch 7 taken 372 times.
9556 if (!opt_initialize && (dd::upgrade::no_server_upgrade_required() ||
9058
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 174 times.
177 opt_upgrade_mode == UPGRADE_MINIMAL))
9059
1/2
✓ Branch 0 taken 9007 times.
✗ Branch 1 not taken.
9007 servers_init(nullptr);
9060
9061
2/2
✓ Branch 0 taken 9167 times.
✓ Branch 1 taken 212 times.
9379 if (!opt_noacl) {
9062
1/2
✓ Branch 0 taken 9167 times.
✗ Branch 1 not taken.
9167 udf_read_functions_table();
9063 }
9064
9065
1/2
✓ Branch 0 taken 9379 times.
✗ Branch 1 not taken.
9379 init_status_vars();
9066 /* If running with --initialize, do not start replication. */
9067
2/2
✓ Branch 0 taken 198 times.
✓ Branch 1 taken 9181 times.
9379 if (opt_initialize) opt_skip_replica_start = true;
9068
9069
1/2
✓ Branch 0 taken 9379 times.
✗ Branch 1 not taken.
9379 check_binlog_cache_size(nullptr);
9070
1/2
✓ Branch 0 taken 9379 times.
✗ Branch 1 not taken.
9379 check_binlog_stmt_cache_size(nullptr);
9071
9072
1/2
✓ Branch 0 taken 9379 times.
✗ Branch 1 not taken.
9379 binlog_unsafe_map_init();
9073
9074 /* If running with --initialize, do not start replication. */
9075
2/2
✓ Branch 0 taken 9181 times.
✓ Branch 1 taken 198 times.
9379 if (!opt_initialize) {
9076 // Make @@replica_skip_errors show the nice human-readable value.
9077
1/2
✓ Branch 0 taken 9181 times.
✗ Branch 1 not taken.
9181 set_replica_skip_errors(&opt_replica_skip_errors);
9078 /*
9079 Group replication filters should be discarded before init_replica(),
9080 otherwise the pre-configured filters will be referenced by group
9081 replication channels.
9082 */
9083
1/2
✓ Branch 0 taken 9181 times.
✗ Branch 1 not taken.
9181 rpl_channel_filters.discard_group_replication_filters();
9084
9085 /*
9086 init_replica() must be called after the thread keys are created.
9087 */
9088
2/2
✓ Branch 0 taken 9173 times.
✓ Branch 1 taken 8 times.
9181 if (server_id != 0)
9089
1/2
✓ Branch 0 taken 9173 times.
✗ Branch 1 not taken.
9173 init_replica(); /* Ignoring errors while configuring replication. */
9090
9091 /*
9092 If the user specifies a per-channel replication filter through a
9093 command-line option (or in a configuration file) for a slave
9094 replication channel which does not exist as of now (i.e not
9095 present in slave info tables yet), then the per-channel
9096 replication filter is discarded with a warning.
9097 If the user specifies a per-channel replication filter through
9098 a command-line option (or in a configuration file) for group
9099 replication channels 'group_replication_recovery' and
9100 'group_replication_applier' which is disallowed, then the
9101 per-channel replication filter is discarded with a warning.
9102 */
9103
1/2
✓ Branch 0 taken 9181 times.
✗ Branch 1 not taken.
9181 rpl_channel_filters.discard_all_unattached_filters();
9104 }
9105
9106 #ifdef WITH_LOCK_ORDER
9107 if (!opt_initialize) {
9108 LO_activate();
9109 }
9110 #endif /* WITH_LOCK_ORDER */
9111
9112 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
9113
1/2
✓ Branch 0 taken 9379 times.
✗ Branch 1 not taken.
9379 initialize_performance_schema_acl(opt_initialize);
9114 #endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
9115
9116
1/2
✓ Branch 0 taken 9379 times.
✗ Branch 1 not taken.
9379 initialize_information_schema_acl();
9117
9118
4/6
✓ Branch 0 taken 9379 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1506 times.
✓ Branch 3 taken 7873 times.
✓ Branch 4 taken 1506 times.
✗ Branch 5 not taken.
9379 (void)RUN_HOOK(server_state, after_recovery, (nullptr));
9119
9120
5/8
✓ Branch 0 taken 9167 times.
✓ Branch 1 taken 212 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9167 times.
✓ Branch 4 taken 9379 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 9379 times.
9379 if (Events::init(opt_noacl || opt_initialize))
9121 unireg_abort(MYSQLD_ABORT_EXIT);
9122
9123 #ifndef _WIN32
9124 // Start signal handler thread.
9125
1/2
✓ Branch 0 taken 9379 times.
✗ Branch 1 not taken.
9379 start_signal_handler();
9126 #endif
9127
9128
2/4
✓ Branch 0 taken 9379 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9379 times.
18758 if (opt_authentication_policy &&
9129
2/4
✓ Branch 0 taken 9379 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9379 times.
9379 validate_authentication_policy(opt_authentication_policy)) {
9130 /* --authentication_policy is set to invalid value */
9131 LogErr(ERROR_LEVEL, ER_INVALID_AUTHENTICATION_POLICY);
9132 return 1;
9133 } else {
9134 /* update the value */
9135
1/2
✓ Branch 0 taken 9379 times.
✗ Branch 1 not taken.
9379 update_authentication_policy();
9136 }
9137
9138 #ifdef WITH_WSREP /* WSREP AFTER SE */
9139 /*
9140 Initialize wsrep_provider before processing of persisted variables
9141 allowing wsrep provider options related variables like
9142 'wsrep_max_ws_size_update' to be persisted as well
9143 */
9144
2/2
✓ Branch 0 taken 9181 times.
✓ Branch 1 taken 198 times.
9379 if (!opt_initialize) {
9145
1/2
✓ Branch 0 taken 9181 times.
✗ Branch 1 not taken.
9181 wsrep_init_globals();
9146
3/4
✓ Branch 0 taken 9181 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8747 times.
✓ Branch 3 taken 434 times.
9181 if (!wsrep_before_SE()) {
9147
1/2
✓ Branch 0 taken 8747 times.
✗ Branch 1 not taken.
8747 wsrep_init_startup(false);
9148 }
9149 }
9150 #endif /* WITH_WSREP */
9151
9152 /* set all persistent options */
9153
2/4
✓ Branch 0 taken 9379 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9379 times.
9379 if (persisted_variables_cache.set_persisted_options(false)) {
9154 LogErr(ERROR_LEVEL, ER_CANT_SET_UP_PERSISTED_VALUES);
9155 flush_error_log_messages();
9156 return 1;
9157 }
9158
9159 #ifdef WITH_WSREP /* WSREP AFTER SE */
9160
2/2
✓ Branch 0 taken 9181 times.
✓ Branch 1 taken 198 times.
9379 if (!opt_initialize) {
9161
1/2
✓ Branch 0 taken 9181 times.
✗ Branch 1 not taken.
9181 wsrep_create_appliers(wsrep_slave_threads - 1);
9162 }
9163 #endif /* WITH_WSREP */
9164
9165 /*
9166 Invoke the bootstrap thread, if required.
9167 */
9168
1/2
✓ Branch 0 taken 9181 times.
✗ Branch 1 not taken.
9379 process_bootstrap();
9169
9170 /*
9171 Event must be invoked after error_handler_hook is assigned to
9172 my_message_sql, otherwise my_message will not cause the event to abort.
9173 */
9174 9181 void *argv_p = argv;
9175
2/4
✓ Branch 0 taken 9181 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9181 times.
9181 if (mysql_audit_notify(AUDIT_EVENT(MYSQL_AUDIT_SERVER_STARTUP_STARTUP),
9176 static_cast<const char **>(argv_p), argc))
9177 unireg_abort(MYSQLD_ABORT_EXIT);
9178
9179 #ifdef _WIN32
9180 create_shutdown_and_restart_thread();
9181 #endif
9182
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 9177 times.
9181 if (mysqld_process_must_end_at_startup) {
9183 #if !defined(_WIN32)
9184
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4 if (opt_daemonize) mysqld::runtime::signal_parent(pipe_write_fd, 1);
9185 #endif
9186
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
4 unireg_abort(MYSQLD_SUCCESS_EXIT);
9187 }
9188
9189
1/2
✓ Branch 0 taken 9177 times.
✗ Branch 1 not taken.
9177 start_handle_manager();
9190
9191
1/2
✓ Branch 0 taken 9177 times.
✗ Branch 1 not taken.
9177 create_compress_gtid_table_thread();
9192
9193
1/2
✓ Branch 0 taken 9177 times.
✗ Branch 1 not taken.
18354 LogEvent()
9194
1/2
✓ Branch 0 taken 9177 times.
✗ Branch 1 not taken.
9177 .type(LOG_TYPE_ERROR)
9195
1/2
✓ Branch 0 taken 9177 times.
✗ Branch 1 not taken.
9177 .subsys(LOG_SUBSYSTEM_TAG)
9196
1/2
✓ Branch 0 taken 9177 times.
✗ Branch 1 not taken.
9177 .prio(SYSTEM_LEVEL)
9197
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9177 times.
✓ Branch 2 taken 9177 times.
✗ Branch 3 not taken.
9177 .lookup(ER_SERVER_STARTUP_MSG, my_progname, server_version,
9198 #ifdef HAVE_SYS_UN_H
9199 (opt_initialize ? "" : mysqld_unix_port),
9200 #else
9201 "",
9202 #endif
9203 mysqld_port, MYSQL_COMPILATION_COMMENT_SERVER);
9204
9205
4/4
✓ Branch 0 taken 8848 times.
✓ Branch 1 taken 329 times.
✓ Branch 2 taken 27 times.
✓ Branch 3 taken 8821 times.
9177 if (!opt_disable_networking && my_admin_bind_addr_str)
9206
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
54 LogEvent()
9207
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 .type(LOG_TYPE_ERROR)
9208
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 .subsys(LOG_SUBSYSTEM_TAG)
9209
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 .prio(SYSTEM_LEVEL)
9210
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 .lookup(ER_SERVER_STARTUP_ADMIN_INTERFACE, my_admin_bind_addr_str,
9211 mysqld_admin_port, MYSQL_COMPILATION_COMMENT);
9212
9213 #if defined(_WIN32)
9214 if (windows_service) {
9215 Service_status_msg s("R");
9216 send_service_status(s);
9217 }
9218 #endif
9219
9220
1/2
✓ Branch 0 taken 9177 times.
✗ Branch 1 not taken.
9177 server_components_initialized();
9221
9222 /*
9223 Set opt_super_readonly here because if opt_super_readonly is set
9224 in get_option, it will create problem while setting up event scheduler.
9225 */
9226 9177 set_super_read_only_post_init();
9227
9228
3/8
✓ Branch 0 taken 9177 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9177 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9177 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
9177 DBUG_PRINT("info", ("Block, listening for incoming connections"));
9229
9230
1/2
✓ Branch 0 taken 9177 times.
✗ Branch 1 not taken.
9177 (void)MYSQL_SET_STAGE(0, __FILE__, __LINE__);
9231
9232 9177 server_operational_state = SERVER_OPERATING;
9233
1/2
✓ Branch 0 taken 9177 times.
✗ Branch 1 not taken.
9177 sysd::notify("READY=1\nSTATUS=Server is operational\nMAIN_PID=", getpid(),
9234 "\n");
9235
9236
4/6
✓ Branch 0 taken 9177 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1506 times.
✓ Branch 3 taken 7671 times.
✓ Branch 4 taken 1506 times.
✗ Branch 5 not taken.
9177 (void)RUN_HOOK(server_state, before_handle_connection, (nullptr));
9237
9238 #if defined(_WIN32)
9239 if (mysqld_socket_acceptor != nullptr)
9240 mysqld_socket_acceptor->check_and_spawn_admin_connection_handler_thread();
9241 setup_conn_event_handler_threads();
9242 #else
9243
1/2
✓ Branch 0 taken 9177 times.
✗ Branch 1 not taken.
9177 mysql_mutex_lock(&LOCK_socket_listener_active);
9244 // Make it possible for the signal handler to kill the listener.
9245 9177 socket_listener_active = true;
9246
1/2
✓ Branch 0 taken 9177 times.
✗ Branch 1 not taken.
9177 mysql_mutex_unlock(&LOCK_socket_listener_active);
9247
9248
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9175 times.
9177 if (opt_daemonize) {
9249
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (nstdout != nullptr) {
9250 // Show the pid on stdout if daemonizing and connected to tty
9251 fprintf(nstdout, "mysqld is running as pid %lu\n", current_pid);
9252 fclose(nstdout);
9253 nstdout = nullptr;
9254 }
9255
9256
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 mysqld::runtime::signal_parent(pipe_write_fd, 1);
9257 }
9258
9259
1/2
✓ Branch 0 taken 9177 times.
✗ Branch 1 not taken.
9177 mysqld_socket_acceptor->check_and_spawn_admin_connection_handler_thread();
9260
1/2
✓ Branch 0 taken 7851 times.
✗ Branch 1 not taken.
9177 mysqld_socket_acceptor->connection_event_loop();
9261 #endif /* _WIN32 */
9262 7851 server_operational_state = SERVER_SHUTTING_DOWN;
9263
1/2
✓ Branch 0 taken 7851 times.
✗ Branch 1 not taken.
7851 sysd::notify("STOPPING=1\nSTATUS=Server shutdown in progress\n");
9264
9265
3/8
✓ Branch 0 taken 7851 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7851 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 7851 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
7851 DBUG_PRINT("info", ("No longer listening for incoming connections"));
9266
9267
1/2
✓ Branch 0 taken 7851 times.
✗ Branch 1 not taken.
7851 mysql_audit_notify(MYSQL_AUDIT_SERVER_SHUTDOWN_SHUTDOWN,
9268 MYSQL_AUDIT_SERVER_SHUTDOWN_REASON_SHUTDOWN,
9269 MYSQLD_SUCCESS_EXIT);
9270
9271
1/2
✓ Branch 0 taken 7851 times.
✗ Branch 1 not taken.
7851 terminate_compress_gtid_table_thread();
9272 /*
9273 Save set of GTIDs of the last binlog into gtid_executed table
9274 on server shutdown.
9275 */
9276
2/2
✓ Branch 0 taken 7717 times.
✓ Branch 1 taken 134 times.
7851 if (opt_bin_log)
9277
3/4
✓ Branch 0 taken 7717 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 7714 times.
7717 if (gtid_state->save_gtids_of_last_binlog_into_table())
9278
8/16
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
3 LogErr(WARNING_LEVEL, ER_CANT_SAVE_GTIDS);
9279
9280 #ifndef _WIN32
9281
1/2
✓ Branch 0 taken 7851 times.
✗ Branch 1 not taken.
7851 mysql_mutex_lock(&LOCK_socket_listener_active);
9282 // Notify the signal handler that we have stopped listening for connections.
9283 7851 socket_listener_active = false;
9284
1/2
✓ Branch 0 taken 7851 times.
✗ Branch 1 not taken.
7851 mysql_cond_broadcast(&COND_socket_listener_active);
9285
1/2
✓ Branch 0 taken 7851 times.
✗ Branch 1 not taken.
7851 mysql_mutex_unlock(&LOCK_socket_listener_active);
9286 #endif // !_WIN32
9287
9288 #ifdef HAVE_PSI_THREAD_INTERFACE
9289 /*
9290 Disable the main thread instrumentation,
9291 to avoid recording events during the shutdown.
9292 */
9293
1/2
✓ Branch 0 taken 7851 times.
✗ Branch 1 not taken.
7851 PSI_THREAD_CALL(delete_current_thread)();
9294 #endif /* HAVE_PSI_THREAD_INTERFACE */
9295
9296
3/8
✓ Branch 0 taken 7851 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7851 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 7851 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
7851 DBUG_PRINT("info", ("Waiting for shutdown proceed"));
9297 7851 int ret = 0;
9298 #ifdef _WIN32
9299 if (shutdown_restart_thr_handle.handle)
9300 ret = my_thread_join(&shutdown_restart_thr_handle, NULL);
9301 shutdown_restart_thr_handle.handle = NULL;
9302 if (0 != ret)
9303 LogErr(WARNING_LEVEL, ER_CANT_JOIN_SHUTDOWN_THREAD, "shutdown ", ret);
9304 #else
9305
1/2
✓ Branch 0 taken 7851 times.
✗ Branch 1 not taken.
7851 if (signal_thread_id.thread != 0)
9306
1/2
✓ Branch 0 taken 7846 times.
✗ Branch 1 not taken.
7851 ret = my_thread_join(&signal_thread_id, nullptr);
9307 7846 signal_thread_id.thread = 0;
9308
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7846 times.
7846 if (0 != ret)
9309 LogErr(WARNING_LEVEL, ER_CANT_JOIN_SHUTDOWN_THREAD, "signal_", ret);
9310 #endif // _WIN32
9311
9312
1/2
✓ Branch 0 taken 7833 times.
✗ Branch 1 not taken.
7846 clean_up(true);
9313 7833 mysqld_exit(signal_hand_thr_exit_code);
9314 }
9315
9316 /****************************************************************************
9317 Main and thread entry function for Win32
9318 (all this is needed only to run mysqld as a service on WinNT)
9319 ****************************************************************************/
9320
9321 #if defined(_WIN32)
9322
9323 bool is_windows_service() { return windows_service; }
9324
9325 NTService *get_win_service_ptr() { return &Service; }
9326
9327 int mysql_service(void *p) {
9328 int my_argc;
9329 char **my_argv;
9330
9331 if (use_opt_args) {
9332 my_argc = opt_argc;
9333 my_argv = opt_argv;
9334 } else if (is_mysqld_monitor()) {
9335 my_argc = Service.my_argc;
9336 my_argv = Service.my_argv;
9337 } else {
9338 my_argc = my_global_argc;
9339 my_argv = my_global_argv;
9340 }
9341
9342 if (!mysqld_early_option) {
9343 int res = start_monitor();
9344 if (res != -1) {
9345 deinitialize_mysqld_monitor();
9346 return res;
9347 }
9348 }
9349
9350 if (my_thread_init()) {
9351 flush_error_log_messages();
9352 return 1;
9353 }
9354
9355 win_main(my_argc, my_argv);
9356
9357 my_thread_end();
9358 return 0;
9359 }
9360
9361 /* Quote string if it contains space, else copy */
9362
9363 static char *add_quoted_string(char *to, const char *from, char *to_end) {
9364 uint length = (uint)(to_end - to);
9365
9366 if (!strchr(from, ' ')) return strmake(to, from, length - 1);
9367 return strxnmov(to, length - 1, "\"", from, "\"", NullS);
9368 }
9369
9370 /**
9371 Handle basic handling of services, like installation and removal.
9372
9373 @param argv Pointer to argument list
9374 @param servicename Internal name of service
9375 @param displayname Display name of service (in taskbar ?)
9376 @param file_path Path to this program
9377 @param startup_option Startup option to mysqld
9378
9379 @retval
9380 0 option handled
9381 @retval
9382 1 Could not handle option
9383 */
9384
9385 static bool default_service_handling(char **argv, const char *servicename,
9386 const char *displayname,
9387 const char *file_path,
9388 const char *extra_opt,
9389 const char *account_name) {
9390 char path_and_service[FN_REFLEN + FN_REFLEN + 32], *pos, *end;
9391 const char *opt_delim;
9392 end = path_and_service + sizeof(path_and_service) - 3;
9393
9394 /* We have to quote filename if it contains spaces */
9395 pos = add_quoted_string(path_and_service, file_path, end);
9396 if (extra_opt && *extra_opt) {
9397 /*
9398 Add option after file_path. There will be zero or one extra option. It's
9399 assumed to be --defaults-file=file but isn't checked. The variable (not
9400 the option name) should be quoted if it contains a string.
9401 */
9402 *pos++ = ' ';
9403 if (opt_delim = strchr(extra_opt, '=')) {
9404 size_t length = ++opt_delim - extra_opt;
9405 pos = my_stpnmov(pos, extra_opt, length);
9406 } else
9407 opt_delim = extra_opt;
9408
9409 pos = add_quoted_string(pos, opt_delim, end);
9410 }
9411 /* We must have servicename last */
9412 *pos++ = ' ';
9413 (void)add_quoted_string(pos, servicename, end);
9414
9415 if (Service.got_service_option(argv, "install")) {
9416 Service.Install(1, servicename, displayname, path_and_service,
9417 account_name);
9418 return 0;
9419 }
9420 if (Service.got_service_option(argv, "install-manual")) {
9421 Service.Install(0, servicename, displayname, path_and_service,
9422 account_name);
9423 return 0;
9424 }
9425 if (Service.got_service_option(argv, "remove")) {
9426 Service.Remove(servicename);
9427 return 0;
9428 }
9429 return 1;
9430 }
9431
9432 int mysqld_main(int argc, char **argv) {
9433 bool mysqld_monitor = false;
9434 mysqld_early_option = is_early_option(argc, argv);
9435
9436 if (!mysqld_early_option) {
9437 initialize_mysqld_monitor();
9438 mysqld_monitor = is_mysqld_monitor();
9439 }
9440
9441 if (mysqld_early_option || !mysqld_monitor) {
9442 /*
9443 When several instances are running on the same machine, we
9444 need to have an unique named hEventShudown through the
9445 application PID e.g.: MySQLShutdown1890; MySQLShutdown2342
9446 */
9447
9448 longlong10_to_str(GetCurrentProcessId(),
9449 my_stpcpy(shutdown_event_name, "MYSQLShutdown"), 10);
9450 longlong10_to_str(GetCurrentProcessId(),
9451 my_stpcpy(restart_event_name, "MYSQLRestart"), 10);
9452 }
9453
9454 /* Must be initialized early for comparison of service name */
9455 system_charset_info = &my_charset_utf8_general_ci;
9456
9457 if (mysqld_early_option || !mysqld_monitor) {
9458 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
9459 pre_initialize_performance_schema();
9460 #endif /*WITH_PERFSCHEMA_STORAGE_ENGINE */
9461
9462 if (my_init()) {
9463 LogErr(ERROR_LEVEL, ER_MYINIT_FAILED);
9464 flush_error_log_messages();
9465 return 1;
9466 }
9467 }
9468
9469 if (mysqld_monitor) /* true NT family */
9470 {
9471 char file_path[FN_REFLEN];
9472 my_path(file_path, argv[0], ""); /* Find name in path */
9473 fn_format(file_path, argv[0], file_path, "",
9474 MY_REPLACE_DIR | MY_UNPACK_FILENAME | MY_RESOLVE_SYMLINKS);
9475
9476 if (argc == 2) {
9477 if (!default_service_handling(argv, MYSQL_SERVICENAME, MYSQL_SERVICENAME,
9478 file_path, "", NULL))
9479 return 0;
9480 if (Service.IsService(argv[1])) /* Start an optional service */
9481 {
9482 /*
9483 Only add the service name to the groups read from the config file
9484 if it's not "MySQL". (The default service name should be 'mysqld'
9485 but we started a bad tradition by calling it MySQL from the start
9486 and we are now stuck with it.
9487 */
9488 if (my_strcasecmp(system_charset_info, argv[1], "mysql"))
9489 load_default_groups[load_default_groups_sz - 2] = argv[1];
9490 windows_service = true;
9491
9492 Service.Init(argv[1], mysql_service);
9493 return 0;
9494 }
9495 } else if (argc == 3) /* install or remove any optional service */
9496 {
9497 if (!default_service_handling(argv, argv[2], argv[2], file_path, "",
9498 NULL))
9499 return 0;
9500 if (Service.IsService(argv[2])) {
9501 /*
9502 mysqld was started as
9503 mysqld --defaults-file=my_path\my.ini service-name
9504 */
9505 use_opt_args = 1;
9506 opt_argc = 2; // Skip service-name
9507 opt_argv = argv;
9508 windows_service = true;
9509 if (my_strcasecmp(system_charset_info, argv[2], "mysql"))
9510 load_default_groups[load_default_groups_sz - 2] = argv[2];
9511 Service.Init(argv[2], mysql_service);
9512 return 0;
9513 }
9514 } else if (argc == 4 || argc == 5) {
9515 /*
9516 This may seem strange, because we handle --local-service while
9517 preserving 4.1's behavior of allowing any one other argument that is
9518 passed to the service on startup. (The assumption is that this is
9519 --defaults-file=file, but that was not enforced in 4.1, so we don't
9520 enforce it here.)
9521 */
9522 const char *extra_opt = NullS;
9523 const char *account_name = NullS;
9524 int index;
9525 for (index = 3; index < argc; index++) {
9526 if (!strcmp(argv[index], "--local-service"))
9527 account_name = "NT AUTHORITY\\LocalService";
9528 else
9529 extra_opt = argv[index];
9530 }
9531
9532 if (argc == 4 || account_name)
9533 if (!default_service_handling(argv, argv[2], argv[2], file_path,
9534 extra_opt, account_name))
9535 return 0;
9536 } else if (argc == 1 && Service.IsService(MYSQL_SERVICENAME)) {
9537 /* start the default service */
9538 windows_service = true;
9539 Service.Init(MYSQL_SERVICENAME, mysql_service);
9540 return 0;
9541 }
9542 }
9543
9544 // Set windows_service value in mysqld
9545 if (!mysqld_monitor) {
9546 windows_service = is_monitor_win_service();
9547
9548 if (windows_service) {
9549 if (argc == 2 && Service.IsService(argv[1])) {
9550 if (my_strcasecmp(system_charset_info, argv[1], "mysql"))
9551 load_default_groups[load_default_groups_sz - 2] = argv[1];
9552 argc--;
9553
9554 } else if (argc == 3 && Service.IsService(argv[2])) {
9555 /*
9556 mysqld was started as
9557 mysqld --defaults-file=my_path\my.ini service-name
9558 */
9559 if (my_strcasecmp(system_charset_info, argv[2], "mysql"))
9560 load_default_groups[load_default_groups_sz - 2] = argv[2];
9561 argc--;
9562 }
9563 }
9564
9565 my_global_argc = argc;
9566 my_global_argv = argv;
9567 } else {
9568 Service.my_argc = argc;
9569 Service.my_argv = argv;
9570 }
9571
9572 return mysql_service(NULL);
9573 }
9574 #endif // _WIN32
9575
9576 /**
9577 Execute the bootstrap thread, if required.
9578
9579 When mysqld is started with --initialize only,
9580 the bootstrap thread executes
9581 - compiled in statements.
9582 - create the non-DD based INFORMATION_SCHEMA.
9583 and the server exits.
9584
9585 When mysqld is started with --init-file only,
9586 the bootstrap thread executes SQL statements provided
9587 in the input text file,
9588 and the server continues and serves requests.
9589
9590 When mysqld is started with both --initialize and --init-file,
9591 the bootstrap thread:
9592 - executes compiled in statements,
9593 - executes SQL statements in the --init-file.
9594 - creates the non-DD based INFORMATION_SCHEMA.
9595 The server then exits.
9596
9597 Compiled in statements are executed in a privileged mode,
9598 with SYSTEM_THREAD_SERVER_INITIALIZE.
9599
9600 @see handle_bootstrap_impl
9601 */
9602 9379 static void process_bootstrap() {
9603 9379 MYSQL_FILE *init_file = nullptr;
9604 9379 const char *init_file_name = nullptr;
9605 enum_thread_type system_thread;
9606 9379 bool need_bootstrap = false;
9607
9608
2/2
✓ Branch 0 taken 198 times.
✓ Branch 1 taken 9181 times.
9379 if (opt_initialize) {
9609 // Make sure we can process SIGHUP during bootstrap.
9610 198 server_components_initialized();
9611 198 need_bootstrap = true;
9612 198 system_thread = SYSTEM_THREAD_SERVER_INITIALIZE;
9613 } else {
9614 9181 system_thread = SYSTEM_THREAD_INIT_FILE;
9615 }
9616
9617
2/2
✓ Branch 0 taken 494 times.
✓ Branch 1 taken 8885 times.
9379 if (opt_init_file != nullptr) {
9618
1/2
✓ Branch 0 taken 494 times.
✗ Branch 1 not taken.
494 if (*opt_init_file != '\0') {
9619 494 init_file_name = opt_init_file;
9620
7/14
✓ Branch 0 taken 494 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 494 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 494 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 494 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 494 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 494 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 494 times.
✗ Branch 13 not taken.
494 LogErr(INFORMATION_LEVEL, ER_BEG_INITFILE, init_file_name);
9621
9622 494 init_file = mysql_file_fopen(key_file_init, init_file_name, O_RDONLY,
9623 MYF(MY_WME));
9624 494 need_bootstrap = true;
9625 }
9626
9627
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 494 times.
494 if (init_file == nullptr) {
9628 LogErr(ERROR_LEVEL, ER_INIT_CANT_OPEN_BOOTSTRAP_FILE, init_file_name);
9629 unireg_abort(MYSQLD_ABORT_EXIT);
9630 }
9631 }
9632
9633
2/2
✓ Branch 0 taken 523 times.
✓ Branch 1 taken 8856 times.
9379 if (need_bootstrap) {
9634 523 bool error = bootstrap::run_bootstrap_thread(init_file_name, init_file,
9635 nullptr, system_thread);
9636
9637
2/2
✓ Branch 0 taken 494 times.
✓ Branch 1 taken 29 times.
523 if (init_file != nullptr) {
9638 494 mysql_file_fclose(init_file, MYF(MY_WME));
9639
7/14
✓ Branch 0 taken 494 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 494 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 494 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 494 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 494 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 494 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 494 times.
✗ Branch 13 not taken.
494 LogErr(INFORMATION_LEVEL, ER_END_INITFILE, init_file_name);
9640 }
9641
9642
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 514 times.
523 if (error) {
9643 /* Abort during system initialization, but not init-file execution */
9644
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
9 if (system_thread == SYSTEM_THREAD_SERVER_INITIALIZE) {
9645 3 unireg_abort(MYSQLD_ABORT_EXIT);
9646 }
9647 }
9648
9649
2/2
✓ Branch 0 taken 195 times.
✓ Branch 1 taken 325 times.
520 if (opt_initialize) {
9650 // Create non DD based system views during --initialize.
9651 195 error = dd::init(
9652 dd::enum_dd_init_type::DD_INITIALIZE_NON_DD_BASED_SYSTEM_VIEWS);
9653
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 195 times.
195 if (error != 0) {
9654 LogErr(ERROR_LEVEL, ER_SYSTEM_VIEW_INIT_FAILED);
9655 unireg_abort(MYSQLD_ABORT_EXIT);
9656 }
9657
9658 195 unireg_abort(MYSQLD_SUCCESS_EXIT);
9659 }
9660 }
9661
9662 9181 return;
9663 }
9664
9665 /****************************************************************************
9666 Handle start options
9667 ******************************************************************************/
9668
9669 /**
9670 Process command line options but use only "help", "initialize",
9671 "initialize-insecure". If one of these options exists then change default
9672 value of log_error_verbosity.
9673 */
9674 10124 static void adjust_log_error_verbosity(vector<my_option> *all_early_options) {
9675
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10124 times.
10124 if (remaining_argc <= 1) return;
9676
9677 /* create a copy of remaining_argv */
9678 10124 int copy_argc = remaining_argc;
9679 10124 vector<char *> copy_argv;
9680
1/2
✓ Branch 0 taken 10124 times.
✗ Branch 1 not taken.
10124 copy_argv.reserve(copy_argc + 1);
9681
3/4
✓ Branch 0 taken 802027 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 802027 times.
✓ Branch 3 taken 10124 times.
812151 for (int i = 0; i < copy_argc; i++) copy_argv.push_back(remaining_argv[i]);
9682
1/2
✓ Branch 0 taken 10124 times.
✗ Branch 1 not taken.
10124 copy_argv.push_back(nullptr);
9683
9684 /* select only "help", "initialize", "initialize-insecure" options */
9685 10124 vector<my_option> init_options;
9686 static const vector<const char *> opt_names{"help", "initialize",
9687
3/8
✓ Branch 0 taken 10124 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10124 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10124 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
10124 "initialize-insecure"};
9688
2/2
✓ Branch 0 taken 232852 times.
✓ Branch 1 taken 10124 times.
242976 for (my_option *opt = my_long_early_options; opt->name != nullptr; opt++)
9689
1/2
✓ Branch 0 taken 232852 times.
✗ Branch 1 not taken.
232852 if (std::find(opt_names.cbegin(), opt_names.cend(), opt->name) !=
9690
2/2
✓ Branch 0 taken 30372 times.
✓ Branch 1 taken 202480 times.
465704 opt_names.cend())
9691
1/2
✓ Branch 0 taken 30372 times.
✗ Branch 1 not taken.
30372 init_options.push_back(*opt);
9692
1/2
✓ Branch 0 taken 10124 times.
✗ Branch 1 not taken.
10124 add_terminator(&init_options);
9693
9694 10124 char **copy_argv_ptr = &copy_argv[0];
9695
1/2
✓ Branch 0 taken 10124 times.
✗ Branch 1 not taken.
10124 int ho_error = handle_options(&copy_argc, &copy_argv_ptr, &init_options[0],
9696 mysqld_get_one_option);
9697
9698
3/4
✓ Branch 0 taken 10124 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10110 times.
✓ Branch 3 taken 14 times.
10124 if ((ho_error == 0) &&
9699
4/4
✓ Branch 0 taken 10099 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 201 times.
✓ Branch 3 taken 9898 times.
10110 (opt_help || opt_initialize || opt_initialize_insecure)) {
9700 /*
9701 Show errors during --help, but mute everything else so the info the
9702 user actually wants isn't lost in the spam. (For --help --verbose,
9703 we need to set up far enough to be able to print variables provided
9704 by plugins, so a good number of warnings/notes might get printed.)
9705 Likewise for --initialize.
9706 */
9707
2/2
✓ Branch 0 taken 22374 times.
✓ Branch 1 taken 226 times.
22600 for (my_option *opt = &(*all_early_options)[0]; opt->name; opt++)
9708
2/2
✓ Branch 0 taken 226 times.
✓ Branch 1 taken 22148 times.
22374 if (!strcmp("log_error_verbosity", opt->name)) {
9709
4/4
✓ Branch 0 taken 215 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 202 times.
✓ Branch 3 taken 13 times.
226 opt->def_value = (opt_initialize || opt_initialize_insecure) ? 2 : 1;
9710 }
9711 }
9712 10124 }
9713
9714 /**
9715 Process command line options flagged as 'early'.
9716 Some components needs to be initialized as early as possible,
9717 because the rest of the server initialization depends on them.
9718 Options that needs to be parsed early includes:
9719 - the performance schema, when compiled in,
9720 - options related to the help,
9721 - options related to the bootstrap
9722 The performance schema needs to be initialized as early as possible,
9723 before to-be-instrumented objects of the server are initialized.
9724 */
9725 10124 static int handle_early_options() {
9726 int ho_error;
9727 10124 vector<my_option> all_early_options;
9728
1/2
✓ Branch 0 taken 10124 times.
✗ Branch 1 not taken.
10124 all_early_options.reserve(100);
9729
9730
1/2
✓ Branch 0 taken 10124 times.
✗ Branch 1 not taken.
10124 my_getopt_register_get_addr(nullptr);
9731 /* Skip unknown options so that they may be processed later */
9732 10124 my_getopt_skip_unknown = true;
9733
9734 /* Add the system variables parsed early */
9735
1/2
✓ Branch 0 taken 10124 times.
✗ Branch 1 not taken.
10124 sys_var_add_options(&all_early_options, sys_var::PARSE_EARLY);
9736
9737 /* Add the command line options parsed early */
9738
2/2
✓ Branch 0 taken 232852 times.
✓ Branch 1 taken 10124 times.
242976 for (my_option *opt = my_long_early_options; opt->name != nullptr; opt++)
9739
1/2
✓ Branch 0 taken 232852 times.
✗ Branch 1 not taken.
232852 all_early_options.push_back(*opt);
9740
9741
1/2
✓ Branch 0 taken 10124 times.
✗ Branch 1 not taken.
10124 add_terminator(&all_early_options);
9742
9743 10124 my_getopt_error_reporter = option_error_reporter;
9744 10124 my_charset_error_reporter = charset_error_reporter;
9745
9746
1/2
✓ Branch 0 taken 10124 times.
✗ Branch 1 not taken.
10124 adjust_log_error_verbosity(&all_early_options);
9747
9748
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
10124 ho_error = handle_options(&remaining_argc, &remaining_argv,
9749 10124 &all_early_options[0], mysqld_get_one_option);
9750
9751
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 if (ho_error == 0) {
9752 /* update verbosity in filter engine, if needed */
9753
1/2
✓ Branch 0 taken 9813 times.
✗ Branch 1 not taken.
9813 log_builtins_filter_update_verbosity(log_error_verbosity);
9754
9755 /* Add back the program name handle_options removes */
9756 9813 remaining_argc++;
9757 9813 remaining_argv--;
9758
9759
2/2
✓ Branch 0 taken 202 times.
✓ Branch 1 taken 9611 times.
9813 if (opt_initialize_insecure) opt_initialize = true;
9760
9761
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9811 times.
9813 if (opt_debugging) {
9762 /* Allow break with SIGINT, no core or stack trace */
9763 2 test_flags |= TEST_SIGINT | TEST_NO_STACKTRACE;
9764 2 test_flags &= ~TEST_CORE_ON_SIGNAL;
9765 }
9766 }
9767
9768 // Swap with an empty vector, i.e. delete elements and free allocated space.
9769 9813 vector<my_option>().swap(all_early_options);
9770
9771 9813 return ho_error;
9772 9813 }
9773
9774 /**
9775 Adjust @c open_files_limit.
9776 Computation is based on:
9777 - @c max_connections,
9778 - @c table_cache_size,
9779 - the platform max open file limit.
9780 */
9781 9808 static void adjust_open_files_limit(ulong *requested_open_files) {
9782 ulong limit_1;
9783 ulong limit_2;
9784 ulong limit_3;
9785 ulong request_open_files;
9786 ulong effective_open_files;
9787
9788 /* MyISAM requires two file handles per table. */
9789 9808 limit_1 = 10 + max_connections + table_cache_size * 2;
9790
9791 /*
9792 We are trying to allocate no less than max_connections*5 file
9793 handles (i.e. we are trying to set the limit so that they will
9794 be available).
9795 */
9796 9808 limit_2 = max_connections * 5;
9797
9798 /* Try to allocate no less than 5000 by default. */
9799
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9807 times.
9808 limit_3 = open_files_limit ? open_files_limit : 5000;
9800
9801 9808 request_open_files = max<ulong>(max<ulong>(limit_1, limit_2), limit_3);
9802
9803 /* Notice: my_set_max_open_files() may return more than requested. */
9804
1/2
✓ Branch 0 taken 9808 times.
✗ Branch 1 not taken.
9808 effective_open_files = my_set_max_open_files(request_open_files);
9805
9806
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9808 times.
9808 if (effective_open_files < request_open_files) {
9807 if (open_files_limit == 0) {
9808 LogErr(WARNING_LEVEL, ER_CHANGED_MAX_OPEN_FILES, effective_open_files,
9809 request_open_files);
9810 } else {
9811 LogErr(WARNING_LEVEL, ER_CANT_INCREASE_MAX_OPEN_FILES,
9812 effective_open_files, request_open_files);
9813 }
9814 }
9815
9816 9808 open_files_limit = effective_open_files;
9817
1/2
✓ Branch 0 taken 9808 times.
✗ Branch 1 not taken.
9808 if (requested_open_files)
9818 9808 *requested_open_files =
9819 9808 min<ulong>(effective_open_files, request_open_files);
9820 9808 }
9821
9822 static constexpr const ulong TABLE_OPEN_CACHE_MIN{400};
9823
9824 9808 static void adjust_max_connections(ulong requested_open_files) {
9825 ulong limit;
9826
9827 9808 limit = requested_open_files - 10 - TABLE_OPEN_CACHE_MIN * 2;
9828
9829
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9808 times.
9808 if (limit < max_connections) {
9830 LogErr(WARNING_LEVEL, ER_CHANGED_MAX_CONNECTIONS, limit, max_connections);
9831
9832 // This can be done unprotected since it is only called on startup.
9833 max_connections = limit;
9834 }
9835 9808 }
9836
9837 9808 static void adjust_table_cache_size(ulong requested_open_files) {
9838 ulong limit;
9839
9840 9808 limit = max<ulong>((requested_open_files - 10 - max_connections) / 2,
9841 TABLE_OPEN_CACHE_MIN);
9842
9843
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9808 times.
9808 if (limit < table_cache_size) {
9844 LogErr(WARNING_LEVEL, ER_CHANGED_TABLE_OPEN_CACHE, limit, table_cache_size);
9845
9846 table_cache_size = limit;
9847 }
9848
9849 9808 table_cache_size_per_instance = table_cache_size / table_cache_instances;
9850 9808 }
9851
9852 9808 static void adjust_table_def_size() {
9853 ulong default_value;
9854 sys_var *var;
9855
9856 9808 default_value = min<ulong>(400 + table_cache_size / 2, 2000);
9857
2/4
✓ Branch 0 taken 9808 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9808 times.
✗ Branch 3 not taken.
9808 var = find_static_system_variable("table_definition_cache");
9858
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9808 times.
9808 assert(var != nullptr);
9859 9808 var->update_default(default_value);
9860
9861
2/2
✓ Branch 0 taken 9806 times.
✓ Branch 1 taken 2 times.
9808 if (!table_definition_cache_specified) table_def_size = default_value;
9862 9808 }
9863
9864 9808 static void adjust_related_options(ulong *requested_open_files) {
9865 /*
9866 In bootstrap, disable grant tables (about to be created)
9867 */
9868
2/2
✓ Branch 0 taken 213 times.
✓ Branch 1 taken 9595 times.
9808 if (opt_initialize) opt_noacl = true;
9869
9870 /* The order is critical here, because of dependencies. */
9871 9808 adjust_open_files_limit(requested_open_files);
9872 9808 adjust_max_connections(*requested_open_files);
9873 9808 adjust_table_cache_size(*requested_open_files);
9874 9808 adjust_table_def_size();
9875 9808 }
9876
9877 vector<my_option> all_options;
9878
9879 struct my_option my_long_early_options[] = {
9880 #if !defined(_WIN32)
9881 {"daemonize", 'D', "Run mysqld as sysv daemon", &opt_daemonize,
9882 &opt_daemonize, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
9883 #endif
9884 {"skip-grant-tables", 0,
9885 "Start without grant tables. This gives all users FULL ACCESS to all "
9886 "tables.",
9887 &opt_noacl, &opt_noacl, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0,
9888 nullptr},
9889 {"help", '?', "Display this help and exit.", &opt_help, &opt_help, nullptr,
9890 GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
9891 {"verbose", 'v', "Used with --help option for detailed help.", &opt_verbose,
9892 &opt_verbose, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
9893 {"version", 'V', "Output version information and exit.", nullptr, nullptr,
9894 nullptr, GET_NO_ARG, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
9895 {"initialize", 'I',
9896 "Create the default database and exit."
9897 " Create a super user with a random expired password and store it into "
9898 "the log.",
9899 &opt_initialize, &opt_initialize, nullptr, GET_BOOL, NO_ARG, 0, 0, 0,
9900 nullptr, 0, nullptr},
9901 {"initialize-insecure", 0,
9902 "Create the default database and exit."
9903 " Create a super user with empty password.",
9904 &opt_initialize_insecure, &opt_initialize_insecure, nullptr, GET_BOOL,
9905 NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
9906 {"keyring-migration-source", OPT_KEYRING_MIGRATION_SOURCE,
9907 "Keyring plugin from where the keys needs to "
9908 "be migrated to. This option must be specified along with "
9909 "--keyring-migration-destination.",
9910 &opt_keyring_migration_source, &opt_keyring_migration_source, nullptr,
9911 GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
9912 {"keyring-migration-destination", OPT_KEYRING_MIGRATION_DESTINATION,
9913 "Keyring plugin to which the keys are "
9914 "migrated to. This option must be specified along with "
9915 "--keyring-migration-source.",
9916 &opt_keyring_migration_destination, &opt_keyring_migration_destination,
9917 nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
9918 {"keyring-migration-user", OPT_KEYRING_MIGRATION_USER,
9919 "User to login to server.", &opt_keyring_migration_user,
9920 &opt_keyring_migration_user, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0,
9921 nullptr, 0, nullptr},
9922 {"keyring-migration-host", OPT_KEYRING_MIGRATION_HOST, "Connect to host.",
9923 &opt_keyring_migration_host, &opt_keyring_migration_host, nullptr, GET_STR,
9924 REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
9925 {"keyring-migration-password", 'p',
9926 "Password to use when connecting to server during keyring migration. "
9927 "If password value is not specified then it will be asked from the tty.",
9928 nullptr, nullptr, nullptr, GET_PASSWORD, OPT_ARG, 0, 0, 0, nullptr, 0,
9929 nullptr},
9930 {"keyring-migration-socket", OPT_KEYRING_MIGRATION_SOCKET,
9931 "The socket file to use for connection.", &opt_keyring_migration_socket,
9932 &opt_keyring_migration_socket, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0,
9933 nullptr, 0, nullptr},
9934 {"keyring-migration-port", OPT_KEYRING_MIGRATION_PORT,
9935 "Port number to use for connection.", &opt_keyring_migration_port,
9936 &opt_keyring_migration_port, nullptr, GET_ULONG, REQUIRED_ARG, 0, 0, 0,
9937 nullptr, 0, nullptr},
9938 {"keyring-migration-to-component", OPT_KEYRING_MIGRATION_TO_COMPONENT,
9939 "Migrate from keyring plugin to keyring component.",
9940 &opt_keyring_migration_to_component, &opt_keyring_migration_to_component,
9941 nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
9942 {"keyring-migration-socket", OPT_KEYRING_MIGRATION_SOCKET,
9943 "The socket file to use for connection.", &opt_keyring_migration_socket,
9944 &opt_keyring_migration_socket, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0,
9945 nullptr, 0, nullptr},
9946 {"keyring-migration-port", OPT_KEYRING_MIGRATION_PORT,
9947 "Port number to use for connection.", &opt_keyring_migration_port,
9948 &opt_keyring_migration_port, nullptr, GET_ULONG, REQUIRED_ARG, 0, 0, 0,
9949 nullptr, 0, nullptr},
9950 {"no-dd-upgrade", 0,
9951 "Abort restart if automatic upgrade or downgrade of the data dictionary "
9952 "is needed. Deprecated option. Use --upgrade=NONE instead.",
9953 &opt_no_dd_upgrade, &opt_no_dd_upgrade, nullptr, GET_BOOL, NO_ARG, 0, 0, 0,
9954 nullptr, 0, nullptr},
9955 {"validate-config", 0,
9956 "Validate the server configuration specified by the user.",
9957 &opt_validate_config, &opt_validate_config, nullptr, GET_BOOL, NO_ARG, 0, 0,
9958 0, nullptr, 0, nullptr},
9959 {"core-file", OPT_WANT_CORE, "Write core on errors.", 0, 0, nullptr,
9960 GET_NO_ARG, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
9961 {"coredumper", OPT_COREDUMPER,
9962 "Use coredumper library to generate coredumps. Specify a path for "
9963 "coredump "
9964 "otherwise it will be generated on datadir",
9965 &opt_libcoredumper_path, &opt_libcoredumper_path, 0, GET_STR, OPT_ARG, 0, 0,
9966 0, 0, 0, 0},
9967 {"skip-stack-trace", OPT_SKIP_STACK_TRACE,
9968 "Don't print a stack trace on failure.", 0, 0, nullptr, GET_NO_ARG, NO_ARG,
9969 0, 0, 0, nullptr, 0, nullptr},
9970 /* We must always support the next option to make scripts like mysqltest
9971 easier to do */
9972 {"gdb", 0, "Set up signals usable for debugging.", &opt_debugging,
9973 &opt_debugging, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
9974 {nullptr, 0, nullptr, nullptr, nullptr, nullptr, GET_NO_ARG, NO_ARG, 0, 0, 0,
9975 nullptr, 0, nullptr}
9976 };
9977
9978 /**
9979 System variables are automatically command-line options (few
9980 exceptions are documented in sys_var.h), so don't need
9981 to be listed here.
9982 */
9983
9984 struct my_option my_long_options[] = {
9985 {"abort-slave-event-count", OPT_ABORT_SLAVE_EVENT_COUNT,
9986 "Option used by mysql-test for debugging and testing of replication."
9987 "This option is deprecated and will be removed in a future version. ",
9988 &abort_slave_event_count, &abort_slave_event_count, nullptr, GET_INT,
9989 REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
9990 {"allow-suspicious-udfs", 0,
9991 "Allows use of UDFs consisting of only one symbol xxx() "
9992 "without corresponding xxx_init() or xxx_deinit(). That also means "
9993 "that one can load any function from any library, for example exit() "
9994 "from libc.so",
9995 &opt_allow_suspicious_udfs, &opt_allow_suspicious_udfs, nullptr, GET_BOOL,
9996 NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
9997 {"ansi", 'a',
9998 "Use ANSI SQL syntax instead of MySQL syntax. This mode "
9999 "will also set transaction isolation level 'serializable'.",
10000 nullptr, nullptr, nullptr, GET_NO_ARG, NO_ARG, 0, 0, 0, nullptr, 0,
10001 nullptr},
10002 /*
10003 Because Sys_var_bit does not support command-line options, we need to
10004 explicitly add one for --autocommit
10005 */
10006 {"autocommit", 0, "Set default value for autocommit (0 or 1)",
10007 &opt_autocommit, &opt_autocommit, nullptr, GET_BOOL, OPT_ARG, 1, 0, 0,
10008 &source_autocommit, /* arg_source, to be copied to Sys_var */
10009 0, nullptr},
10010 {"binlog-do-db", OPT_BINLOG_DO_DB,
10011 "Include only updates to the specified database when writing the "
10012 "binary log.",
10013 nullptr, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
10014 nullptr},
10015 {"binlog-ignore-db", OPT_BINLOG_IGNORE_DB,
10016 "Exclude updates to the specified database when writing the binary "
10017 "log.",
10018 nullptr, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
10019 nullptr},
10020 {"character-set-client-handshake", 0,
10021 "Don't ignore client side character set value sent during handshake.",
10022 &opt_character_set_client_handshake, &opt_character_set_client_handshake,
10023 nullptr, GET_BOOL, NO_ARG, 1, 0, 0, nullptr, 0, nullptr},
10024 {"character-set-filesystem", 0, "Set the filesystem character set.",
10025 &character_set_filesystem_name, &character_set_filesystem_name, nullptr,
10026 GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
10027 {"character-set-server", 'C', "Set the default character set.",
10028 &default_character_set_name, &default_character_set_name, nullptr, GET_STR,
10029 REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
10030 {"chroot", 'r', "Chroot mysqld daemon during startup.", &mysqld_chroot,
10031 &mysqld_chroot, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
10032 nullptr},
10033 {"collation-server", 0, "Set the default collation.",
10034 &default_collation_name, &default_collation_name, nullptr, GET_STR,
10035 REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
10036 {"console", OPT_CONSOLE,
10037 "Write error output on screen; don't remove the console window on "
10038 "windows.",
10039 &opt_console, &opt_console, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0,
10040 nullptr},
10041 /* default-storage-engine should have "MyISAM" as def_value. Instead
10042 of initializing it here it is done in init_common_variables() due
10043 to a compiler bug in Sun Studio compiler. */
10044 {"default-storage-engine", 0, "The default storage engine for new tables",
10045 &default_storage_engine, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0,
10046 nullptr, 0, nullptr},
10047 {"default-tmp-storage-engine", 0,
10048 "The default storage engine for new explicit temporary tables",
10049 &default_tmp_storage_engine, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0,
10050 0, nullptr, 0, nullptr},
10051 {"default-time-zone", 0, "Set the default time zone.", &default_tz_name,
10052 &default_tz_name, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
10053 nullptr},
10054 {"disconnect-slave-event-count", OPT_DISCONNECT_SLAVE_EVENT_COUNT,
10055 "Option used by mysql-test for debugging and testing of replication."
10056 "This option is deprecated and will be removed in a future version.",
10057 &disconnect_slave_event_count, &disconnect_slave_event_count, nullptr,
10058 GET_INT, REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
10059 {"exit-info", 'T', "Used for debugging. Use at your own risk.", nullptr,
10060 nullptr, nullptr, GET_LONG, OPT_ARG, 0, 0, 0, nullptr, 0, nullptr},
10061
10062 {"external-locking", 0,
10063 "Use system (external) locking (disabled by "
10064 "default). With this option enabled you can run myisamchk to test "
10065 "(not repair) tables while the MySQL server is running. Disable with "
10066 "--skip-external-locking.",
10067 &opt_external_locking, &opt_external_locking, nullptr, GET_BOOL, NO_ARG, 0,
10068 0, 0, nullptr, 0, nullptr},
10069 #if defined(HAVE_LINUX_LARGE_PAGES) || defined(HAVE_SOLARIS_LARGE_PAGES)
10070 {"super-large-pages", 0, "Enable support for super large pages.",
10071 &opt_super_large_pages, &opt_super_large_pages, nullptr, GET_BOOL, OPT_ARG,
10072 0, 0, 1, nullptr, 1, nullptr},
10073 #endif
10074 {"language", 'L',
10075 "Client error messages in given language. May be given as a full path. "
10076 "Deprecated. Use --lc-messages-dir instead.",
10077 &lc_messages_dir_ptr, &lc_messages_dir_ptr, nullptr, GET_STR, REQUIRED_ARG,
10078 0, 0, 0, nullptr, 0, nullptr},
10079 {"lc-messages", 0, "Set the language used for the error messages.",
10080 &lc_messages, &lc_messages, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0,
10081 nullptr, 0, nullptr},
10082 {"lc-time-names", 0,
10083 "Set the language used for the month names and the days of the week.",
10084 &lc_time_names_name, &lc_time_names_name, nullptr, GET_STR, REQUIRED_ARG,
10085 0, 0, 0, nullptr, 0, nullptr},
10086 {"log-bin", OPT_BIN_LOG,
10087 "Configures the name prefix to use for binary log files. If the --log-bin "
10088 "option is not supplied, the name prefix defaults to \"binlog\". If the "
10089 "--log-bin option is supplied without argument, the name prefix defaults "
10090 "to \"HOSTNAME-bin\", where HOSTNAME is the machine's hostname. To set a "
10091 "different name prefix for binary log files, use --log-bin=name. To "
10092 "disable "
10093 "binary logging, use the --skip-log-bin or --disable-log-bin option.",
10094 &opt_bin_logname, &opt_bin_logname, nullptr, GET_STR_ALLOC, OPT_ARG, 0, 0,
10095 0, nullptr, 0, nullptr},
10096 {"log-bin-index", 0, "File that holds the names for binary log files.",
10097 &opt_binlog_index_name, &opt_binlog_index_name, nullptr, GET_STR,
10098 REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
10099 {"relay-log-index", 0, "File that holds the names for relay log files.",
10100 &opt_relaylog_index_name, &opt_relaylog_index_name, nullptr, GET_STR,
10101 REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
10102 {"log-isam", OPT_ISAM_LOG, "Log all MyISAM changes to file.",
10103 &myisam_log_filename, &myisam_log_filename, nullptr, GET_STR, OPT_ARG, 0,
10104 0, 0, nullptr, 0, nullptr},
10105 {"log-short-format", 0,
10106 "Don't log extra information to update and slow-query logs.",
10107 &opt_short_log_format, &opt_short_log_format, nullptr, GET_BOOL, NO_ARG, 0,
10108 0, 0, nullptr, 0, nullptr},
10109 {"log-tc", 0,
10110 "Path to transaction coordinator log (used for transactions that affect "
10111 "more than one storage engine, when binary log is disabled).",
10112 &opt_tc_log_file, &opt_tc_log_file, nullptr, GET_STR, REQUIRED_ARG, 0, 0,
10113 0, nullptr, 0, nullptr},
10114 {"log-tc-size", 0, "Size of transaction coordinator log.", &opt_tc_log_size,
10115 &opt_tc_log_size, nullptr, GET_ULONG, REQUIRED_ARG,
10116 TC_LOG_MIN_PAGES *my_getpagesize(), TC_LOG_MIN_PAGES *my_getpagesize(),
10117 ULONG_MAX, nullptr, my_getpagesize(), nullptr},
10118 {"master-info-file", OPT_MASTER_INFO_FILE,
10119 "The path and filename where the replication receiver thread stores "
10120 "connection configuration and positions, in case "
10121 "--master-info-repository=FILE. "
10122 "This option is deprecated and will be removed in a future version.",
10123 &master_info_file, &master_info_file, nullptr, GET_STR, REQUIRED_ARG, 0, 0,
10124 0, nullptr, 0, nullptr},
10125 {"master-retry-count", OPT_MASTER_RETRY_COUNT,
10126 "The number of times this replica will attempt to connect to a source "
10127 "before giving up. "
10128 "This option is deprecated and will be removed in a future version. "
10129 "Use 'CHANGE REPLICATION SOURCE TO SOURCE_RETRY_COUNT = <num>' instead.",
10130 &master_retry_count, &master_retry_count, nullptr, GET_ULONG, REQUIRED_ARG,
10131 3600 * 24, 0, 0, nullptr, 0, nullptr},
10132 {"max-binlog-dump-events", 0,
10133 "Option used by mysql-test for debugging and testing of replication.",
10134 &max_binlog_dump_events, &max_binlog_dump_events, nullptr, GET_INT,
10135 REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
10136 {"memlock", 0, "Lock mysqld in memory.", &locked_in_memory,
10137 &locked_in_memory, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0,
10138 nullptr},
10139 {"old-style-user-limits", OPT_OLD_STYLE_USER_LIMITS,
10140 "Enable old-style user limits (before 5.0.3, user resources were counted "
10141 "for each user + host vs. per account). "
10142 "This option is deprecated and will be removed in a future version.",
10143 &opt_old_style_user_limits, &opt_old_style_user_limits, nullptr, GET_BOOL,
10144 NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
10145 {"port-open-timeout", 0,
10146 "Maximum time in seconds to wait for the port to become free. "
10147 "(Default: No wait).",
10148 &mysqld_port_timeout, &mysqld_port_timeout, nullptr, GET_UINT,
10149 REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
10150 {"replicate-do-db", OPT_REPLICATE_DO_DB,
10151 "Make replication applier threads apply only changes to the specified "
10152 "database. "
10153 "To specify more than one database, use the directive multiple times, "
10154 "once for each database. Note that this will only work if you do not use "
10155 "cross-database queries such as UPDATE some_db.some_table SET foo='bar' "
10156 "while having selected a different or no database. If you need cross "
10157 "database updates to work, make sure you have 3.23.28 or later, and use "
10158 "replicate-wild-do-table=db_name.%.",
10159 nullptr, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
10160 nullptr},
10161 {"replicate-do-table", OPT_REPLICATE_DO_TABLE,
10162 "Make replication applier threads apply only changes to the specified "
10163 "table. "
10164 "To specify more than one table, use the directive multiple times, once "
10165 "for each table. This will work for cross-database updates, in contrast "
10166 "to replicate-do-db.",
10167 nullptr, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
10168 nullptr},
10169 {"replica-enable-event", OPT_REPLICA_ENABLE_EVENT,
10170 "Tells the replication applier thread to enable the events that match "
10171 "the specified wildcard pattern without setting it as SLAVESIDE_DISABLED. "
10172 "To specify more than one event, use the directive multiple times, once "
10173 "for each event. This will work for cross-database events. Example: "
10174 "replica-enable-event=foo%.bar% will enable the events in all "
10175 "databases on replica server that start with 'foo' and whose event names "
10176 "start with 'bar'. It is recommended to use this feature only for "
10177 "read-only events to avoid data inconsistency.",
10178 nullptr, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
10179 nullptr},
10180 {"replicate-ignore-db", OPT_REPLICATE_IGNORE_DB,
10181 "Make replication applier threads skip changes to the specified "
10182 "database. "
10183 "To specify more than one database to ignore, use this option multiple "
10184 "times, once for each database. If there are statements that update "
10185 "multiple databases, this will work correctly only when the source "
10186 "server uses binlog_format=ROW.",
10187 nullptr, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
10188 nullptr},
10189 {"replicate-ignore-table", OPT_REPLICATE_IGNORE_TABLE,
10190 "Make replication applier threads skip changes to the specified table."
10191 "To ignore more than one table, use the option multiple times, once for "
10192 "each table. If there are statements that update multiple tables, this "
10193 "will work correctly only when the source server uses binlog_format=ROW.",
10194 nullptr, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
10195 nullptr},
10196 {"replicate-rewrite-db", OPT_REPLICATE_REWRITE_DB,
10197 "Make replication applier threads rename a database, so changes in one "
10198 "database on the source will be applied in another database on this "
10199 "replica. Example: "
10200 "replicate-rewrite-db=source_db_name->replica_db_name.",
10201 nullptr, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
10202 nullptr},
10203 {"replicate-same-server-id", 0,
10204 "In replication, if set to 1, do not skip events having our server id. "
10205 "Default value is 0 (to break infinite loops in circular replication). "
10206 "Can't be set to 1 if --log-replica-updates is used.",
10207 &replicate_same_server_id, &replicate_same_server_id, nullptr, GET_BOOL,
10208 NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
10209 {"replicate-wild-do-table", OPT_REPLICATE_WILD_DO_TABLE,
10210 "Make replication applier threads apply changes only in tables that "
10211 "match the specified wildcard pattern. To specify more than one pattern, "
10212 "use the option multiple times, once for each pattern. If there are "
10213 "statements that update both tables that are included and excluded by "
10214 "the pattern, this will only work correctly when the source server uses "
10215 "binlog_format=ROW. "
10216 "Example: replicate-wild-do-table=foo%.bar% will "
10217 "replicate only updates to tables in all databases that start with foo "
10218 "and whose table names start with bar.",
10219 nullptr, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
10220 nullptr},
10221 {"replicate-wild-ignore-table", OPT_REPLICATE_WILD_IGNORE_TABLE,
10222 "Make replication applier threads skip changes to tables that match "
10223 "the specified wildcard pattern. To specify more than one pattern, use "
10224 "the option multiple times, once for each pattern. If there are "
10225 "statements that update both tables that are included and tables that "
10226 "are excluded by the pattern, this will only work correctly when the "
10227 "source server uses binlog_format=ROW. "
10228 "Example: when using replicate-wild-ignore-table=foo%.bar%, "
10229 "the applier thread will not apply updates to tables in databases that "
10230 "start with foo and whose table names start with bar.",
10231 nullptr, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
10232 nullptr},
10233 {"safe-user-create", 0,
10234 "Don't allow new user creation by the user who has no write privileges to "
10235 "the mysql.user table.",
10236 &opt_safe_user_create, &opt_safe_user_create, nullptr, GET_BOOL, NO_ARG, 0,
10237 0, 0, nullptr, 0, nullptr},
10238 {"show-replica-auth-info", 0,
10239 "Include user and password in SHOW REPLICAS statements.",
10240 &opt_show_replica_auth_info, &opt_show_replica_auth_info, nullptr,
10241 GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
10242 {"show-slave-auth-info", OPT_SHOW_SLAVE_AUTH_INFO_DEPRECATED,
10243 "This option is deprecated and will be removed in a future version. "
10244 "Use show-replica-auth-info instead.",
10245 &opt_show_replica_auth_info, &opt_show_replica_auth_info, nullptr,
10246 GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
10247 {"skip-host-cache", OPT_SKIP_HOST_CACHE_DEPRECATED,
10248 "Don't cache host names.", nullptr, nullptr, nullptr, GET_NO_ARG, NO_ARG,
10249 0, 0, 0, nullptr, 0, nullptr},
10250 {"skip-new", OPT_SKIP_NEW, "Don't use new, possibly wrong routines.",
10251 nullptr, nullptr, nullptr, GET_NO_ARG, NO_ARG, 0, 0, 0, nullptr, 0,
10252 nullptr},
10253 #if defined(_WIN32)
10254 {"slow-start-timeout", 0,
10255 "Maximum number of milliseconds that the service control manager should "
10256 "wait "
10257 "before trying to kill the windows service during startup"
10258 "(Default: 15000).",
10259 &slow_start_timeout, &slow_start_timeout, 0, GET_ULONG, REQUIRED_ARG, 15000,
10260 0, 0, 0, 0, 0},
10261 #endif
10262 {"sporadic-binlog-dump-fail", 0,
10263 "Option used by mysql-test for debugging and testing of replication.",
10264 &opt_sporadic_binlog_dump_fail, &opt_sporadic_binlog_dump_fail, nullptr,
10265 GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
10266 {"ssl", OPT_USE_SSL,
10267 "Enable SSL for connection (automatically enabled with other flags).",
10268 &opt_use_ssl, &opt_use_ssl, nullptr, GET_BOOL, OPT_ARG, 1, 0, 0, nullptr,
10269 0, nullptr},
10270 {"admin-ssl", OPT_USE_ADMIN_SSL,
10271 "Enable SSL for admin interface (automatically enabled with other flags).",
10272 &opt_use_admin_ssl, &opt_use_admin_ssl, nullptr, GET_BOOL, OPT_ARG, 1, 0,
10273 0, nullptr, 0, nullptr},
10274 #ifdef _WIN32
10275 {"standalone", 0, "Dummy option to start as a standalone program (NT).", 0, 0,
10276 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
10277 {"no-monitor", 0, "Disable monitor process.", &opt_no_monitor,
10278 &opt_no_monitor, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
10279 #endif
10280 {"symbolic-links", 's',
10281 "Enable symbolic link support (deprecated and will be removed in a future"
10282 " release).",
10283 &my_enable_symlinks, &my_enable_symlinks, nullptr, GET_BOOL, NO_ARG, 0, 0, 0,
10284 nullptr, 0, nullptr},
10285 {"sysdate-is-now", 0,
10286 "Non-default option to alias SYSDATE() to NOW() to make it "
10287 "safe-replicable. "
10288 "Since 5.0, SYSDATE() returns a `dynamic' value different for different "
10289 "invocations, even within the same statement.",
10290 &global_system_variables.sysdate_is_now, nullptr, nullptr, GET_BOOL, NO_ARG,
10291 0, 0, 1, nullptr, 1, nullptr},
10292 {"tc-heuristic-recover", 0,
10293 "Decision to use in heuristic recover process. Possible values are OFF, "
10294 "COMMIT or ROLLBACK.",
10295 &tc_heuristic_recover, &tc_heuristic_recover, &tc_heuristic_recover_typelib,
10296 GET_ENUM, REQUIRED_ARG, TC_HEURISTIC_NOT_USED, 0, 0, nullptr, 0, nullptr},
10297 #if defined(ENABLED_DEBUG_SYNC)
10298 {"debug-sync-timeout", OPT_DEBUG_SYNC_TIMEOUT,
10299 "Enable the debug sync facility "
10300 "and optionally specify a default wait timeout in seconds. "
10301 "A zero value keeps the facility disabled.",
10302 &opt_debug_sync_timeout, nullptr, nullptr, GET_UINT, OPT_ARG, 0, 0, UINT_MAX,
10303 nullptr, 0, nullptr},
10304 #endif /* defined(ENABLED_DEBUG_SYNC) */
10305 {"transaction-isolation", 0, "Default transaction isolation level.",
10306 &global_system_variables.transaction_isolation,
10307 &global_system_variables.transaction_isolation, &tx_isolation_typelib,
10308 GET_ENUM, REQUIRED_ARG, ISO_REPEATABLE_READ, 0, 0, nullptr, 0, nullptr},
10309 {"transaction-read-only", 0,
10310 "Default transaction access mode. "
10311 "True if transactions are read-only.",
10312 &global_system_variables.transaction_read_only,
10313 &global_system_variables.transaction_read_only, nullptr, GET_BOOL, OPT_ARG,
10314 0, 0, 0, nullptr, 0, nullptr},
10315 {"user", 'u', "Run mysqld daemon as user.", nullptr, nullptr, nullptr,
10316 GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
10317 {"early-plugin-load", OPT_EARLY_PLUGIN_LOAD,
10318 "Optional semicolon-separated list of plugins to load before storage "
10319 "engine "
10320 "initialization, where each plugin is identified as name=library, where "
10321 "name is the plugin name and library is the plugin library in plugin_dir.",
10322 nullptr, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
10323 nullptr},
10324 {"plugin-load", OPT_PLUGIN_LOAD,
10325 "Optional semicolon-separated list of plugins to load, where each plugin "
10326 "is "
10327 "identified as name=library, where name is the plugin name and library "
10328 "is the plugin library in plugin_dir.",
10329 nullptr, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
10330 nullptr},
10331 {"plugin-load-add", OPT_PLUGIN_LOAD_ADD,
10332 "Optional semicolon-separated list of plugins to load, where each plugin "
10333 "is "
10334 "identified as name=library, where name is the plugin name and library "
10335 "is the plugin library in plugin_dir. This option adds to the list "
10336 "specified by --plugin-load in an incremental way. "
10337 "Multiple --plugin-load-add are supported.",
10338 nullptr, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
10339 nullptr},
10340
10341 {"innodb", OPT_SKIP_INNODB,
10342 "Deprecated option. Provided for backward compatibility only. "
10343 "The option has no effect on the server behaviour. InnoDB is always "
10344 "enabled. "
10345 "The option will be removed in a future release.",
10346 nullptr, nullptr, nullptr, GET_BOOL, OPT_ARG, 0, 0, 0, nullptr, 0, nullptr},
10347
10348 {"upgrade", 0,
10349 "Set server upgrade mode. NONE to abort server if automatic upgrade of "
10350 "the server is needed; MINIMAL to start the server, but skip upgrade "
10351 "steps that are not absolutely necessary; AUTO (default) to upgrade the "
10352 "server if required; FORCE to force upgrade server.",
10353 &opt_upgrade_mode, &opt_upgrade_mode, &upgrade_mode_typelib, GET_ENUM,
10354 REQUIRED_ARG, UPGRADE_AUTO, 0, 0, nullptr, 0, nullptr},
10355
10356 {"utility_user", 0,
10357 "Specifies a MySQL user that will be added to the "
10358 "internal list of users and recognized as the utility user.",
10359 &utility_user, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
10360 {"utility_user_password", 0,
10361 "Specifies the password required for the "
10362 "utility user.",
10363 &utility_user_password, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
10364 {"utility_user_privileges", 0,
10365 "Specifies the privileges that the utility "
10366 "user will have in a comma delimited list. See the manual for a complete "
10367 "list of privileges.",
10368 &utility_user_privileges, 0, &utility_user_privileges_typelib, GET_SET,
10369 REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
10370 {"utility_user_dynamic_privileges", 0,
10371 "Specifies the dynamic privileges that the utility "
10372 "user will have in a comma delimited list. See the manual for a complete "
10373 "list of privileges.",
10374 &utility_user_dynamic_privileges, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0,
10375 0},
10376 {"utility_user_schema_access", 0,
10377 "Specifies the schemas that the utility "
10378 "user has access to in a comma delimited list.",
10379 &utility_user_schema_access, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
10380
10381 {nullptr, 0, nullptr, nullptr, nullptr, nullptr, GET_NO_ARG, NO_ARG, 0, 0, 0,
10382 nullptr, 0, nullptr}
10383 };
10384
10385 143051 static int show_queries(THD *thd, SHOW_VAR *var, char *) {
10386 143051 var->type = SHOW_LONGLONG;
10387 143051 var->value = (char *)&thd->query_id;
10388 143051 return 0;
10389 }
10390
10391 99973 static int show_net_compression(THD *thd, SHOW_VAR *var, char *buff) {
10392 99973 var->type = SHOW_MY_BOOL;
10393 99973 var->value = buff;
10394 99973 *((bool *)buff) = thd->get_protocol()->get_compression();
10395 99973 return 0;
10396 }
10397
10398 99973 static int show_net_compression_algorithm(THD *thd, SHOW_VAR *var, char *buff) {
10399 99973 const char *s = thd->get_protocol()->get_compression_algorithm();
10400 99973 var->type = SHOW_CHAR;
10401 99973 var->value = buff;
10402
2/2
✓ Branch 0 taken 85 times.
✓ Branch 1 taken 99888 times.
99973 sprintf(buff, "%s", (s ? s : ""));
10403 99973 return 0;
10404 }
10405
10406 99973 static int show_net_compression_level(THD *thd, SHOW_VAR *var, char *buff) {
10407 99973 var->type = SHOW_INT;
10408 99973 var->value = buff;
10409 99973 unsigned int *value = reinterpret_cast<unsigned int *>(buff);
10410 99973 *value = thd->get_protocol()->get_compression_level();
10411 99973 return 0;
10412 }
10413
10414 142385 static int show_starttime(THD *thd, SHOW_VAR *var, char *buff) {
10415 142385 var->type = SHOW_LONGLONG;
10416 142385 var->value = buff;
10417 142385 *((longlong *)buff) =
10418 142385 (longlong)(thd->query_start_in_secs() - server_start_time);
10419 142385 return 0;
10420 }
10421
10422 142386 static int show_max_used_connections_time(THD *thd, SHOW_VAR *var, char *buff) {
10423 MYSQL_TIME max_used_connections_time;
10424 142386 var->type = SHOW_CHAR;
10425 142386 var->value = buff;
10426
1/2
✓ Branch 0 taken 142386 times.
✗ Branch 1 not taken.
142386 thd->variables.time_zone->gmt_sec_to_TIME(
10427 &max_used_connections_time,
10428 Connection_handler_manager::max_used_connections_time);
10429
1/2
✓ Branch 0 taken 142386 times.
✗ Branch 1 not taken.
142386 my_datetime_to_str(max_used_connections_time, buff, 0);
10430 142386 return 0;
10431 }
10432
10433 142385 static int show_num_thread_running(THD *, SHOW_VAR *var, char *buff) {
10434 142385 var->type = SHOW_LONGLONG;
10435 142385 var->value = buff;
10436 142385 long long *value = reinterpret_cast<long long *>(buff);
10437 142385 *value = static_cast<long long>(
10438 142385 Global_THD_manager::get_instance()->get_num_thread_running());
10439 142385 return 0;
10440 }
10441
10442 142385 static int show_num_thread_created(THD *, SHOW_VAR *var, char *buff) {
10443 142385 var->type = SHOW_LONG;
10444 142385 var->value = buff;
10445 142385 long *value = reinterpret_cast<long *>(buff);
10446 142385 *value = static_cast<long>(
10447 142385 Global_THD_manager::get_instance()->get_num_thread_created());
10448 142385 return 0;
10449 }
10450
10451 142388 static int show_thread_id_count(THD *, SHOW_VAR *var, char *buff) {
10452 142388 var->type = SHOW_LONG;
10453 142388 var->value = buff;
10454 142388 long *value = reinterpret_cast<long *>(buff);
10455 142388 *value = static_cast<long>(
10456 142388 Global_THD_manager::get_instance()->get_thread_id() - 1);
10457 142388 return 0;
10458 }
10459
10460 142388 static int show_aborted_connects(THD *, SHOW_VAR *var, char *buff) {
10461 142388 var->type = SHOW_LONG;
10462 142388 var->value = buff;
10463 142388 long *value = reinterpret_cast<long *>(buff);
10464 142388 *value = static_cast<long>(
10465 142388 Connection_handler_manager::get_instance()->aborted_connects());
10466 142388 return 0;
10467 }
10468
10469 #ifdef WITH_WSREP
10470 /*
10471 like init_slave_thread(), rpl_slave.cc
10472 */
10473
10474 1085 static int init_wsrep_thread(THD *thd) {
10475
1/2
✓ Branch 0 taken 1099 times.
✗ Branch 1 not taken.
1085 DBUG_ENTER("init_wsrep_thread");
10476 #if !defined(NDEBUG)
10477 1099 int simulate_error = 0;
10478 #endif
10479 1099 thd->thd_tx_priority = 1;
10480 1099 thd->system_thread = SYSTEM_THREAD_SLAVE_WORKER;
10481
10482
1/2
✓ Branch 0 taken 1097 times.
✗ Branch 1 not taken.
1099 thd->security_context()->skip_grants();
10483
2/4
✓ Branch 0 taken 1095 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1099 times.
✗ Branch 3 not taken.
1097 thd->get_protocol_classic()->init_net(0);
10484 #ifdef GALERA
10485 thd->slave_thread = true;
10486 #endif /* GALERA */
10487 1099 thd->enable_slow_log = opt_log_slow_replica_statements;
10488
1/2
✓ Branch 0 taken 1098 times.
✗ Branch 1 not taken.
1099 set_slave_thread_options(thd);
10489
1/2
✓ Branch 0 taken 1097 times.
✗ Branch 1 not taken.
1098 thd->get_protocol_classic()->set_client_capabilities(CLIENT_LOCAL_FILES);
10490
10491 /*
10492 Replication threads are:
10493 - background threads in the server, not user sessions,
10494 - yet still assigned a PROCESSLIST_ID,
10495 for historical reasons (displayed in SHOW PROCESSLIST).
10496 */
10497
1/2
✓ Branch 0 taken 1099 times.
✗ Branch 1 not taken.
1097 thd->set_new_thread_id();
10498
10499 #ifdef HAVE_PSI_INTERFACE
10500 /*
10501 Populate the PROCESSLIST_ID in the instrumentation.
10502 */
10503
1/2
✓ Branch 0 taken 1099 times.
✗ Branch 1 not taken.
1099 struct PSI_thread *psi = PSI_THREAD_CALL(get_thread)();
10504
1/2
✓ Branch 0 taken 1099 times.
✗ Branch 1 not taken.
1099 PSI_THREAD_CALL(set_thread_id)(psi, thd->thread_id());
10505 #endif /* HAVE_PSI_INTERFACE */
10506
10507
2/4
✓ Branch 0 taken 1099 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1099 times.
1099 DBUG_EXECUTE_IF("simulate_wsrep_slave_error_on_init", simulate_error |= 1;);
10508
1/2
✓ Branch 0 taken 1099 times.
✗ Branch 1 not taken.
1099 wsrep_assign_from_threadvars(thd);
10509
1/2
✓ Branch 0 taken 1099 times.
✗ Branch 1 not taken.
1099 wsrep_store_threadvars(thd);
10510 #if !defined(NDEBUG)
10511
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1099 times.
1099 if (simulate_error) {
10512 DBUG_RETURN(-1);
10513 }
10514 #endif
10515
10516 // THD_STAGE_INFO(thd, stage_waiting_for_the_next_event_in_relay_log);
10517
10518
1/2
✓ Branch 0 taken 1099 times.
✗ Branch 1 not taken.
1099 thd->set_time();
10519 /* Do not use user-supplied timeout value for system threads. */
10520 1099 thd->variables.lock_wait_timeout = LONG_TIMEOUT;
10521
1/2
✓ Branch 0 taken 1099 times.
✗ Branch 1 not taken.
1099 DBUG_RETURN(0);
10522 }
10523
10524 1088 extern "C" void *start_wsrep_THD(void *arg) {
10525 THD *thd;
10526 1088 bool thd_added = false;
10527
10528 1088 Wsrep_thd_args *thd_args = (Wsrep_thd_args *)arg;
10529
10530 1088 Global_THD_manager *thd_manager = Global_THD_manager::get_instance();
10531
2/4
✓ Branch 0 taken 1099 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1099 times.
1099 if (my_thread_init()) {
10532 WSREP_ERROR("Failed to initialize wsrep-thread context");
10533 return (NULL);
10534 }
10535
10536
2/4
✓ Branch 0 taken 1099 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1087 times.
✗ Branch 3 not taken.
1099 thd = new THD(false, true); // note that contructor of THD uses DBUG_ !
10537 // (not enablin plugins, is applier)
10538 1087 thd->thread_stack = (char *)&thd; // remember where our stack is
10539
10540
2/4
✓ Branch 0 taken 1099 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1099 times.
1087 if (init_wsrep_thread(thd)) {
10541 WSREP_WARN("Failed during wsrep thread initialization");
10542 goto err;
10543 }
10544
10545 1099 thd->real_id = pthread_self(); // Keep purify happy
10546
10547
3/8
✓ Branch 0 taken 1099 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1099 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1099 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
1099 DBUG_PRINT("wsrep", (("creating thread %u"), thd->thread_id()));
10548
10549 /* from bootstrap()... */
10550 // thd->bootstrap=1;
10551
2/4
✓ Branch 0 taken 1099 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1099 times.
✗ Branch 3 not taken.
1099 thd->get_protocol_classic()->set_max_packet_size(replica_max_allowed_packet +
10552 MAX_LOG_EVENT_HEADER);
10553 // thd->security_context->master_access= ~(ulong)0;
10554
10555 /* handle_one_connection() again... */
10556 1099 thd->set_proc_info(nullptr);
10557 1099 memset(thd->wsrep_info, 0, sizeof(thd->wsrep_info));
10558
1/2
✓ Branch 0 taken 1099 times.
✗ Branch 1 not taken.
1099 thd->set_command(COM_SLEEP);
10559
1/2
✓ Branch 0 taken 1099 times.
✗ Branch 1 not taken.
1099 thd->init_query_mem_roots();
10560
10561 /* wsrep_running_threads counter is managed in thd_manager */
10562
1/2
✓ Branch 0 taken 1099 times.
✗ Branch 1 not taken.
1099 thd_manager->add_thd(thd);
10563 1099 thd_added = true;
10564
10565 #ifndef SKIP_INNODB_HP
10566 /* set priority */
10567 1099 thd->thd_tx_priority = 1;
10568 #endif
10569
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1099 times.
1099 THD_CHECK_SENTRY(thd);
10570
10571
1/2
✓ Branch 0 taken 1091 times.
✗ Branch 1 not taken.
1099 thd_args->fun()(thd, thd_args->args());
10572
10573 /* Wsrep may reset globals during thread context switches, store globals
10574 before cleanup. */
10575
1/2
✓ Branch 0 taken 1089 times.
✗ Branch 1 not taken.
1091 wsrep_store_threadvars(thd);
10576
10577 1089 err:
10578
1/2
✓ Branch 0 taken 1093 times.
✗ Branch 1 not taken.
1089 thd->clear_error();
10579 1093 thd->set_catalog(NULL_CSTR);
10580
1/2
✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
1091 thd->reset_query();
10581
1/2
✓ Branch 0 taken 1093 times.
✗ Branch 1 not taken.
1092 thd->reset_db(NULL_CSTR);
10582
1/2
✓ Branch 0 taken 1093 times.
✗ Branch 1 not taken.
1093 close_connection(thd, 0, false, false);
10583
10584 1093 thd->temporary_tables = 0; // remove tempation from destructor to close them
10585
10586 // Note: We can't call THD destructor without crashing
10587 // if plugins have not been initialized. However, in most of the
10588 // cases this means that pre SE initialization SST failed and
10589 // we are going to exit anyway.
10590
2/2
✓ Branch 0 taken 1089 times.
✓ Branch 1 taken 4 times.
1093 if (dynamic_plugins_are_initialized) {
10591
2/4
✓ Branch 0 taken 1088 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1090 times.
✗ Branch 3 not taken.
1089 thd->get_protocol_classic()->end_net();
10592
1/2
✓ Branch 0 taken 1091 times.
✗ Branch 1 not taken.
1090 thd->release_resources();
10593
10594
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1091 times.
1091 THD_CHECK_SENTRY(thd);
10595
1/2
✓ Branch 0 taken 1091 times.
✗ Branch 1 not taken.
1091 if (thd_added) {
10596
1/2
✓ Branch 0 taken 1091 times.
✗ Branch 1 not taken.
1091 thd_manager->remove_thd(thd);
10597 }
10598 } else {
10599 // TODO: lightweight cleanup to get rid of:
10600 // 'Error in my_thread_global_end(): 2 threads didn't exit'
10601 // at server shutdown
10602
10603
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (thd_added) {
10604
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 thd->release_resources();
10605
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 thd_manager->remove_thd(thd);
10606 }
10607 }
10608
10609 /*
10610 The thd can only be destructed after indirect references
10611 through mi->rli->info_thd are cleared: mi->rli->info_thd= NULL.
10612
10613 For instance, user thread might be issuing show_slave_status
10614 and attempting to read mi->rli->info_thd->get_proc_info().
10615 Therefore thd must only be deleted after info_thd is set
10616 to NULL.
10617 */
10618
2/2
✓ Branch 0 taken 1093 times.
✓ Branch 1 taken 2 times.
1095 delete thd;
10619
2/2
✓ Branch 0 taken 1091 times.
✓ Branch 1 taken 1 times.
1092 delete static_cast<Wsrep_thd_args*>(arg);
10620
10621
1/2
✓ Branch 0 taken 1093 times.
✗ Branch 1 not taken.
1094 my_thread_end();
10622 #if OPENSSL_VERSION_NUMBER < 0x10100000L
10623 ERR_remove_thread_state(0);
10624 #endif /* OPENSSL_VERSION_NUMBER < 0x10100000L */
10625 1093 my_thread_exit(0);
10626
10627 return (NULL);
10628 }
10629
10630 640 static void wsrep_close_thread(THD *thd) {
10631 640 thd->killed = THD::KILL_CONNECTION;
10632
10633 640 mysql_mutex_lock(&thd->LOCK_thd_data);
10634
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 633 times.
640 if (thd->current_cond) {
10635 7 mysql_mutex_lock(thd->current_mutex);
10636 7 mysql_cond_broadcast(thd->current_cond);
10637 7 mysql_mutex_unlock(thd->current_mutex);
10638 }
10639 640 mysql_mutex_unlock(&thd->LOCK_thd_data);
10640 640 }
10641
10642 116 static bool have_committing_connections() {
10643 // Find_thd_committing find_thd_committing();
10644 116 Find_wsrep_thd find_thd_committing(COMMITTING);
10645
10646 THD_ptr tmp =
10647
1/2
✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
116 Global_THD_manager::get_instance()->find_thd(&find_thd_committing);
10648
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 116 times.
116 if (tmp.get()) return true;
10649 116 return false;
10650 116 }
10651
10652 58 int wsrep_wait_committing_connections_close(int wait_time) {
10653 58 int sleep_time = 100;
10654
10655
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 58 times.
58 while (have_committing_connections() && wait_time > 0) {
10656 WSREP_DEBUG(
10657 "Waiting (%d micro-secs) for committing transaction to close....",
10658 wait_time);
10659 my_sleep(sleep_time);
10660 wait_time -= sleep_time;
10661 }
10662
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
58 if (have_committing_connections()) {
10663 return 1;
10664 }
10665 58 return 0;
10666 }
10667
10668 36 void wsrep_close_client_connections(bool, bool server_shutdown) {
10669 36 Global_THD_manager *thd_manager = Global_THD_manager::get_instance();
10670
10671 /*
10672 * wsrep_close_client_connections can be used when there is a cluster
10673 * reconfiguration or when we set wsrep_reject_queries=ALL_KILL
10674 * on those cases if we are using thread pooling,
10675 * we cannot close the connections abruptly otherwise the thread pool workers
10676 * won't get signaled and will hang forever when we shutdown the server.
10677 * Sending a kill signal and awaking the thread.
10678 */
10679
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 sql_print_information("Giving %d client threads a chance to die gracefully",
10680 static_cast<int>(thd_manager->get_thd_count()));
10681
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 Set_wsrep_kill_client_conn set_wsrep_kill_client_conn;
10682
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 thd_manager->do_for_all_thd(&set_wsrep_kill_client_conn);
10683
2/4
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
36 if (thd_manager->get_thd_count() > 0) sleep(2); // Give threads time to die
10684
10685
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 Call_wsrep_close_client_conn call_wsrep_close_client_conn(server_shutdown);
10686
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 thd_manager->do_for_all_thd(&call_wsrep_close_client_conn);
10687 36 }
10688
10689 640 void wsrep_close_applier(THD *thd) {
10690
11/20
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 606 times.
✓ Branch 2 taken 34 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 34 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 34 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 34 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 34 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 34 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 34 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 34 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 34 times.
640 WSREP_DEBUG("Closing applier %u", thd->thread_id());
10691 640 wsrep_close_thread(thd);
10692 640 }
10693
10694 468 static void wsrep_close_threads(THD *) {
10695 468 Global_THD_manager *thd_manager = Global_THD_manager::get_instance();
10696
10697
1/2
✓ Branch 0 taken 468 times.
✗ Branch 1 not taken.
468 Call_wsrep_close_wsrep_threads call_wsrep_close_wsrep_threads;
10698
1/2
✓ Branch 0 taken 468 times.
✗ Branch 1 not taken.
468 thd_manager->do_for_all_thd(&call_wsrep_close_wsrep_threads);
10699 468 }
10700
10701 void wsrep_close_applier_threads(int) {
10702 Global_THD_manager *thd_manager = Global_THD_manager::get_instance();
10703
10704 Call_wsrep_close_wsrep_threads call_wsrep_close_wsrep_threads;
10705 thd_manager->do_for_all_thd(&call_wsrep_close_wsrep_threads);
10706 }
10707
10708 465 void wsrep_wait_appliers_close(THD *thd) {
10709
10/18
✓ Branch 0 taken 465 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 465 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 465 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 465 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 465 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 465 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 465 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 465 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 10 times.
✓ Branch 17 taken 455 times.
465 WSREP_INFO("Waiting for active wsrep applier to exit");
10710
10711 while (true) {
10712 483 Find_wsrep_thd find_wsrep_thd(APPLIER);
10713
10714 int count =
10715
1/2
✓ Branch 0 taken 483 times.
✗ Branch 1 not taken.
483 Global_THD_manager::get_instance()->count_if_thd(&find_wsrep_thd);
10716
10717 /* rollback + post-rollback thread are terminated later */
10718
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 465 times.
483 if (count > 2) {
10719
10/22
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 18 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 18 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 18 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 18 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 18 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 18 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 18 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
18 WSREP_INFO("Waiting for (%d) applier thread(s) to terminate", count - 1);
10720
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 sleep(1);
10721 } else {
10722
12/22
✓ Branch 0 taken 465 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 465 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 465 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 465 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 465 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 465 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 465 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 465 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 465 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 10 times.
✓ Branch 19 taken 455 times.
✓ Branch 20 taken 10 times.
✗ Branch 21 not taken.
465 WSREP_INFO(
10723 "All applier thread terminated. Will now terminate rollback thread");
10724 465 break;
10725 }
10726
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 465 times.
501 }
10727
10728 /* Now kill remaining wsrep threads: rollbacker + post-rollback */
10729 465 wsrep_close_threads(thd);
10730
10731 465 uint retry_counter = 5;
10732
1/2
✓ Branch 0 taken 886 times.
✗ Branch 1 not taken.
886 while (retry_counter) {
10733 886 Find_wsrep_thd find_wsrep_thd(APPLIER);
10734
3/4
✓ Branch 0 taken 886 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 421 times.
✓ Branch 3 taken 465 times.
886 if (Global_THD_manager::get_instance()->count_if_thd(&find_wsrep_thd) > 0) {
10735
12/22
✓ Branch 0 taken 421 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 421 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 421 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 421 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 421 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 421 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 421 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 421 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 421 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 5 times.
✓ Branch 19 taken 416 times.
✓ Branch 20 taken 5 times.
✗ Branch 21 not taken.
421 WSREP_INFO("Waiting for rollback thread to terminate");
10736
1/2
✓ Branch 0 taken 421 times.
✗ Branch 1 not taken.
421 sleep(1);
10737 421 retry_counter--;
10738 } else {
10739
12/22
✓ Branch 0 taken 465 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 465 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 465 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 465 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 465 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 465 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 465 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 465 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 465 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 10 times.
✓ Branch 19 taken 455 times.
✓ Branch 20 taken 10 times.
✗ Branch 21 not taken.
465 WSREP_INFO("Rollback thread terminated");
10740 465 break;
10741 }
10742
2/2
✓ Branch 0 taken 421 times.
✓ Branch 1 taken 465 times.
886 }
10743
10744
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 465 times.
465 if (retry_counter == 0)
10745 WSREP_INFO("Waited too long to terminate rollback thread before giving up");
10746 465 }
10747
10748 void wsrep_kill_mysql(THD *) {
10749 if (mysqld_server_started) {
10750 WSREP_INFO("Starting Shutdown");
10751 kill_mysql();
10752 } else {
10753 unireg_abort(1);
10754 }
10755 }
10756 #endif /* WITH_WSREP */
10757
10758 142388 static int show_acl_cache_items_count(THD *, SHOW_VAR *var, char *buff) {
10759 142388 var->type = SHOW_LONG;
10760 142388 var->value = buff;
10761 142388 long *value = reinterpret_cast<long *>(buff);
10762 142388 *value = static_cast<long>(get_global_acl_cache_size());
10763 142388 return 0;
10764 }
10765
10766 142388 static int show_connection_errors_max_connection(THD *, SHOW_VAR *var,
10767 char *buff) {
10768 142388 var->type = SHOW_LONG;
10769 142388 var->value = buff;
10770 142388 long *value = reinterpret_cast<long *>(buff);
10771 142388 *value = static_cast<long>(Connection_handler_manager::get_instance()
10772 142388 ->connection_errors_max_connection());
10773 142388 return 0;
10774 }
10775
10776 142388 static int show_connection_errors_query_block(THD *, SHOW_VAR *var,
10777 char *buff) {
10778 142388 var->type = SHOW_LONG;
10779 142388 var->value = buff;
10780 142388 long *value = reinterpret_cast<long *>(buff);
10781 142388 *value = static_cast<long>(get_connection_errors_query_block());
10782 142388 return 0;
10783 }
10784
10785 142388 static int show_connection_errors_accept(THD *, SHOW_VAR *var, char *buff) {
10786 142388 var->type = SHOW_LONG;
10787 142388 var->value = buff;
10788 142388 long *value = reinterpret_cast<long *>(buff);
10789 142388 *value = static_cast<long>(get_connection_errors_accept());
10790 142388 return 0;
10791 }
10792
10793 142388 static int show_connection_errors_tcpwrap(THD *, SHOW_VAR *var, char *buff) {
10794 142388 var->type = SHOW_LONG;
10795 142388 var->value = buff;
10796 142388 long *value = reinterpret_cast<long *>(buff);
10797 142388 *value = static_cast<long>(get_connection_errors_tcpwrap());
10798 142388 return 0;
10799 }
10800
10801 #ifdef ENABLED_PROFILING
10802 142385 static int show_flushstatustime(THD *thd, SHOW_VAR *var, char *buff) {
10803 142385 var->type = SHOW_LONGLONG;
10804 142385 var->value = buff;
10805 142385 *((longlong *)buff) =
10806 142385 (longlong)(thd->query_start_in_secs() - flush_status_time);
10807 142385 return 0;
10808 }
10809 #endif
10810
10811 #ifndef NDEBUG
10812 284770 static int show_replica_rows_last_search_algorithm_used(THD *, SHOW_VAR *var,
10813 char *buff) {
10814 284770 uint res = replica_rows_last_search_algorithm_used;
10815 284770 const char *s =
10816 ((res == Rows_log_event::ROW_LOOKUP_TABLE_SCAN)
10817
2/2
✓ Branch 0 taken 284316 times.
✓ Branch 1 taken 454 times.
569086 ? "TABLE_SCAN"
10818
2/2
✓ Branch 0 taken 4868 times.
✓ Branch 1 taken 279448 times.
284316 : ((res == Rows_log_event::ROW_LOOKUP_HASH_SCAN) ? "HASH_SCAN"
10819 : "INDEX_SCAN"));
10820
10821 284770 var->type = SHOW_CHAR;
10822 284770 var->value = buff;
10823 284770 sprintf(buff, "%s", s);
10824
10825 284770 return 0;
10826 }
10827
10828 142386 static int show_ongoing_automatic_gtid_violating_transaction_count(
10829 THD *, SHOW_VAR *var, char *buf) {
10830 142386 var->type = SHOW_CHAR;
10831 142386 var->value = buf;
10832 142386 sprintf(buf, "%d",
10833 gtid_state->get_automatic_gtid_violating_transaction_count());
10834 142386 return 0;
10835 }
10836
10837 142386 static int show_ongoing_anonymous_gtid_violating_transaction_count(
10838 THD *, SHOW_VAR *var, char *buf) {
10839 142386 var->type = SHOW_CHAR;
10840 142386 var->value = buf;
10841 142386 sprintf(buf, "%d",
10842 gtid_state->get_anonymous_gtid_violating_transaction_count());
10843 142386 return 0;
10844 }
10845
10846 #endif
10847
10848 142386 static int show_ongoing_anonymous_transaction_count(THD *, SHOW_VAR *var,
10849 char *buf) {
10850 142386 var->type = SHOW_CHAR;
10851 142386 var->value = buf;
10852 142386 sprintf(buf, "%d", gtid_state->get_anonymous_ownership_count());
10853 142386 return 0;
10854 }
10855
10856 143052 static int show_open_tables(THD *, SHOW_VAR *var, char *buff) {
10857 143052 var->type = SHOW_LONG;
10858 143052 var->value = buff;
10859 143052 *((long *)buff) = (long)table_cache_manager.cached_tables();
10860 143052 return 0;
10861 }
10862
10863 142385 static int show_prepared_stmt_count(THD *, SHOW_VAR *var, char *buff) {
10864 142385 var->type = SHOW_LONG;
10865 142385 var->value = buff;
10866 142385 mysql_mutex_lock(&LOCK_prepared_stmt_count);
10867 142385 *((long *)buff) = (long)prepared_stmt_count;
10868 142385 mysql_mutex_unlock(&LOCK_prepared_stmt_count);
10869 142385 return 0;
10870 }
10871
10872 142388 static int show_global_mem_counter(THD *, SHOW_VAR *var, char *buff) {
10873 142388 var->type = SHOW_LONGLONG;
10874 142388 var->value = buff;
10875 142388 MUTEX_LOCK(lock, &LOCK_global_conn_mem_limit);
10876 142388 *((longlong *)buff) = (longlong)global_conn_mem_counter;
10877 284776 return 0;
10878 142388 }
10879
10880 142386 static int show_table_definitions(THD *, SHOW_VAR *var, char *buff) {
10881 142386 var->type = SHOW_LONG;
10882 142386 var->value = buff;
10883 142386 *((long *)buff) = (long)cached_table_definitions();
10884 142386 return 0;
10885 }
10886
10887 /*
10888 Functions relying on SSL
10889 Note: In the show_ssl_* functions, we need to check if we have a
10890 valid vio-object since this isn't always true, specifically
10891 when session_status or global_status is requested from
10892 inside an Event.
10893 */
10894 143051 static int show_ssl_get_version(THD *thd, SHOW_VAR *var, char *) {
10895 143051 SSL_handle ssl = thd->get_ssl();
10896 143051 var->type = SHOW_CHAR;
10897
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 142859 times.
143051 if (ssl)
10898 192 var->value = const_cast<char *>(SSL_get_version(ssl));
10899 else
10900 142859 var->value = const_cast<char *>("");
10901 143051 return 0;
10902 }
10903
10904 143051 static int show_ssl_session_reused(THD *thd, SHOW_VAR *var, char *buff) {
10905 143051 SSL_handle ssl = thd->get_ssl();
10906 143051 var->type = SHOW_LONG;
10907 143051 var->value = buff;
10908
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 142859 times.
143051 if (ssl)
10909 192 *((long *)buff) = (long)SSL_session_reused(ssl);
10910 else
10911 142859 *((long *)buff) = 0;
10912 143051 return 0;
10913 }
10914
10915 143051 static int show_ssl_get_default_timeout(THD *thd, SHOW_VAR *var, char *buff) {
10916 143051 SSL_handle ssl = thd->get_ssl();
10917 143051 var->type = SHOW_LONG;
10918 143051 var->value = buff;
10919
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 142859 times.
143051 if (ssl)
10920 192 *((long *)buff) = (long)SSL_get_default_timeout(ssl);
10921 else
10922 142859 *((long *)buff) = 0;
10923 143051 return 0;
10924 }
10925
10926 143051 static int show_ssl_get_verify_mode(THD *thd, SHOW_VAR *var, char *buff) {
10927 143051 SSL_handle ssl = thd->get_ssl();
10928 143051 var->type = SHOW_LONG;
10929 143051 var->value = buff;
10930
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 142859 times.
143051 if (ssl)
10931 192 *((long *)buff) = (long)SSL_get_verify_mode(ssl);
10932 else
10933 142859 *((long *)buff) = 0;
10934 143051 return 0;
10935 }
10936
10937 143051 static int show_ssl_get_verify_depth(THD *thd, SHOW_VAR *var, char *buff) {
10938 143051 SSL_handle ssl = thd->get_ssl();
10939 143051 var->type = SHOW_LONG;
10940 143051 var->value = buff;
10941
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 142859 times.
143051 if (ssl)
10942 192 *((long *)buff) = (long)SSL_get_verify_depth(ssl);
10943 else
10944 142859 *((long *)buff) = 0;
10945 143051 return 0;
10946 }
10947
10948 143051 static int show_ssl_get_cipher(THD *thd, SHOW_VAR *var, char *) {
10949 143051 SSL_handle ssl = thd->get_ssl();
10950 143051 var->type = SHOW_CHAR;
10951
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 142859 times.
143051 if (ssl)
10952 192 var->value = const_cast<char *>(SSL_get_cipher(ssl));
10953 else
10954 142859 var->value = const_cast<char *>("");
10955 143051 return 0;
10956 }
10957
10958 143051 static int show_ssl_get_cipher_list(THD *thd, SHOW_VAR *var, char *buff) {
10959 143051 SSL_handle ssl = thd->get_ssl();
10960 143051 var->type = SHOW_CHAR;
10961 143051 var->value = buff;
10962
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 142859 times.
143051 if (ssl) {
10963 int i;
10964 const char *p;
10965 192 char *end = buff + SHOW_VAR_FUNC_BUFF_SIZE;
10966
5/6
✓ Branch 0 taken 5835 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 5835 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5835 times.
✓ Branch 5 taken 192 times.
6027 for (i = 0; (p = SSL_get_cipher_list(ssl, i)) && buff < end; i++) {
10967 5835 buff = my_stpnmov(buff, p, end - buff - 1);
10968 5835 *buff++ = ':';
10969 }
10970
1/2
✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
192 if (i) buff--;
10971 }
10972 143051 *buff = 0;
10973 143051 return 0;
10974 }
10975
10976 #ifdef HAVE_POOL_OF_THREADS
10977 142385 static int show_threadpool_idle_threads(THD *thd [[maybe_unused]],
10978 SHOW_VAR *var, char *buff) {
10979 142385 var->type = SHOW_INT;
10980 142385 var->value = buff;
10981 142385 *(int *)buff = tp_get_idle_thread_count();
10982 142385 return 0;
10983 }
10984 #endif
10985
10986 284770 static int show_replica_open_temp_tables(THD *, SHOW_VAR *var, char *buf) {
10987 284770 var->type = SHOW_INT;
10988 284770 var->value = buf;
10989 284770 *((int *)buf) = atomic_replica_open_temp_tables;
10990 284770 return 0;
10991 }
10992 10 bool validate_libcoredumper_path(char *libcoredumper_path) {
10993 /* validate path */
10994
3/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8 times.
10 if (!is_valid_log_name(
10995 libcoredumper_path,
10996 strlen(libcoredumper_path))) { // filename contain .cnf or .ini on it
10997
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 sql_print_error("Variable --coredumper cannot be set to value %s",
10998 libcoredumper_path);
10999 2 return false;
11000 }
11001 char libcoredumper_dir[FN_REFLEN];
11002 size_t libcoredumper_dir_length;
11003 8 size_t opt_libcoredumper_path_length = strlen(libcoredumper_path);
11004
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 (void)dirname_part(libcoredumper_dir, libcoredumper_path,
11005 &libcoredumper_dir_length);
11006
11007
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (!libcoredumper_dir_length) {
11008 sql_print_error("Error processing --coredumper path: %s",
11009 libcoredumper_path);
11010 return false;
11011 }
11012 8 size_t libcoredumper_file_length =
11013 8 opt_libcoredumper_path_length - libcoredumper_dir_length;
11014
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
8 if (libcoredumper_file_length == 0) // path is a directory
11015 {
11016 2 libcoredumper_file_length = 19; // file is set to core.yyyymmddhhmmss
11017 } else {
11018 6 libcoredumper_file_length += 15; // file gets .yyyymmddhhmmss appended
11019 }
11020
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
8 if (opt_libcoredumper_path_length > FN_REFLEN) { // path is too long
11021
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 sql_print_error("Variable --coredumper set to a too long path");
11022 2 return false;
11023 }
11024
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
6 if (libcoredumper_file_length > FN_LEN) { // filename is too long
11025
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 sql_print_error("Variable --coredumper set to a too long filename");
11026 2 return false;
11027 }
11028
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (my_access(libcoredumper_dir, F_OK)) {
11029
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 sql_print_error("Directory specified at --coredumper: %s does not exist",
11030 libcoredumper_dir);
11031 2 return false;
11032 }
11033
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (my_access(libcoredumper_dir, (F_OK | W_OK))) {
11034
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 sql_print_error("Directory specified at --coredumper: %s is not writable",
11035 libcoredumper_dir);
11036 2 return false;
11037 }
11038 if (libcoredumper_dir_length ==
11039 strlen(libcoredumper_path)) { // only dirname was specified, append core
11040 // to libcoredumper_path
11041 strcat(libcoredumper_path, "core");
11042 }
11043 return true;
11044 }
11045
11046 142385 static int show_tls_library_version(THD *, SHOW_VAR *var, char *buff) {
11047 #if OPENSSL_VERSION_NUMBER <= 0x10100000L
11048 strncpy(buff, SSLeay_version(SSLEAY_VERSION), SHOW_VAR_FUNC_BUFF_SIZE);
11049 #else
11050 142385 strncpy(buff, OpenSSL_version(OPENSSL_VERSION), SHOW_VAR_FUNC_BUFF_SIZE);
11051 #endif
11052 142385 buff[SHOW_VAR_FUNC_BUFF_SIZE - 1] = 0;
11053 142385 var->type = SHOW_CHAR;
11054 142385 var->value = buff;
11055 142385 return 0;
11056 }
11057
11058 /*
11059 Variables shown by SHOW STATUS in alphabetical order
11060 */
11061 SHOW_VAR status_vars[] = {
11062 {"Aborted_clients", (char *)&aborted_threads, SHOW_LONG, SHOW_SCOPE_GLOBAL},
11063 {"Aborted_connects", (char *)&show_aborted_connects, SHOW_FUNC,
11064 SHOW_SCOPE_GLOBAL},
11065 {"Acl_cache_items_count", (char *)&show_acl_cache_items_count, SHOW_FUNC,
11066 SHOW_SCOPE_GLOBAL},
11067 #ifndef NDEBUG
11068 {"Ongoing_anonymous_gtid_violating_transaction_count",
11069 (char *)&show_ongoing_anonymous_gtid_violating_transaction_count,
11070 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
11071 #endif //! NDEBUG
11072 {"Ongoing_anonymous_transaction_count",
11073 (char *)&show_ongoing_anonymous_transaction_count, SHOW_FUNC,
11074 SHOW_SCOPE_GLOBAL},
11075 #ifndef NDEBUG
11076 {"Ongoing_automatic_gtid_violating_transaction_count",
11077 (char *)&show_ongoing_automatic_gtid_violating_transaction_count,
11078 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
11079 #endif //! NDEBUG
11080 {"Binlog_cache_disk_use", (char *)&binlog_cache_disk_use, SHOW_LONG,
11081 SHOW_SCOPE_GLOBAL},
11082 {"Binlog_cache_use", (char *)&binlog_cache_use, SHOW_LONG,
11083 SHOW_SCOPE_GLOBAL},
11084 {"Binlog_stmt_cache_disk_use", (char *)&binlog_stmt_cache_disk_use,
11085 SHOW_LONG, SHOW_SCOPE_GLOBAL},
11086 {"Binlog_stmt_cache_use", (char *)&binlog_stmt_cache_use, SHOW_LONG,
11087 SHOW_SCOPE_GLOBAL},
11088 {"Bytes_received", (char *)offsetof(System_status_var, bytes_received),
11089 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11090 {"Bytes_sent", (char *)offsetof(System_status_var, bytes_sent),
11091 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11092 {"Com", (char *)com_status_vars, SHOW_ARRAY, SHOW_SCOPE_ALL},
11093 {"Com_stmt_reprepare",
11094 (char *)offsetof(System_status_var, com_stmt_reprepare), SHOW_LONG_STATUS,
11095 SHOW_SCOPE_ALL},
11096 {"Compression", (char *)&show_net_compression, SHOW_FUNC,
11097 SHOW_SCOPE_SESSION},
11098 {"Compression_algorithm", (char *)&show_net_compression_algorithm,
11099 SHOW_FUNC, SHOW_SCOPE_SESSION},
11100 {"Compression_level", (char *)&show_net_compression_level, SHOW_FUNC,
11101 SHOW_SCOPE_SESSION},
11102 {"Connections", (char *)&show_thread_id_count, SHOW_FUNC,
11103 SHOW_SCOPE_GLOBAL},
11104 {"Connection_errors_accept", (char *)&show_connection_errors_accept,
11105 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
11106 {"Connection_errors_internal", (char *)&connection_errors_internal,
11107 SHOW_LONG, SHOW_SCOPE_GLOBAL},
11108 {"Connection_errors_max_connections",
11109 (char *)&show_connection_errors_max_connection, SHOW_FUNC,
11110 SHOW_SCOPE_GLOBAL},
11111 {"Connection_errors_peer_address", (char *)&connection_errors_peer_addr,
11112 SHOW_LONG, SHOW_SCOPE_GLOBAL},
11113 {"Connection_errors_select", (char *)&show_connection_errors_query_block,
11114 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
11115 {"Connection_errors_tcpwrap", (char *)&show_connection_errors_tcpwrap,
11116 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
11117 {"Created_tmp_disk_tables",
11118 (char *)offsetof(System_status_var, created_tmp_disk_tables),
11119 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11120 {"Created_tmp_files", (char *)&my_tmp_file_created, SHOW_LONG,
11121 SHOW_SCOPE_GLOBAL},
11122 {"Created_tmp_tables",
11123 (char *)offsetof(System_status_var, created_tmp_tables),
11124 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11125 {"Delayed_errors", (char *)&delayed_insert_errors, SHOW_LONG,
11126 SHOW_SCOPE_GLOBAL},
11127 {"Delayed_insert_threads", (char *)&delayed_insert_threads,
11128 SHOW_LONG_NOFLUSH, SHOW_SCOPE_GLOBAL},
11129 {"Delayed_writes", (char *)&delayed_insert_writes, SHOW_LONG,
11130 SHOW_SCOPE_GLOBAL},
11131 {"Error_log_buffered_bytes", (char *)&log_sink_pfs_buffered_bytes,
11132 SHOW_LONG_NOFLUSH, SHOW_SCOPE_GLOBAL},
11133 {"Error_log_buffered_events", (char *)&log_sink_pfs_buffered_events,
11134 SHOW_LONG_NOFLUSH, SHOW_SCOPE_GLOBAL},
11135 {"Error_log_expired_events", (char *)&log_sink_pfs_expired_events,
11136 SHOW_LONG, SHOW_SCOPE_GLOBAL},
11137 {"Error_log_latest_write", (char *)&log_sink_pfs_latest_timestamp,
11138 SHOW_LONGLONG, SHOW_SCOPE_GLOBAL},
11139 {"Flush_commands", (char *)&refresh_version, SHOW_LONG_NOFLUSH,
11140 SHOW_SCOPE_GLOBAL},
11141 {"Global_connection_memory", (char *)&show_global_mem_counter, SHOW_FUNC,
11142 SHOW_SCOPE_GLOBAL},
11143 {"Handler_commit", (char *)offsetof(System_status_var, ha_commit_count),
11144 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11145 {"Handler_delete", (char *)offsetof(System_status_var, ha_delete_count),
11146 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11147 {"Handler_discover", (char *)offsetof(System_status_var, ha_discover_count),
11148 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11149 {"Handler_external_lock",
11150 (char *)offsetof(System_status_var, ha_external_lock_count),
11151 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11152 {"Handler_mrr_init",
11153 (char *)offsetof(System_status_var, ha_multi_range_read_init_count),
11154 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11155 {"Handler_prepare", (char *)offsetof(System_status_var, ha_prepare_count),
11156 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11157 {"Handler_read_first",
11158 (char *)offsetof(System_status_var, ha_read_first_count),
11159 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11160 {"Handler_read_key", (char *)offsetof(System_status_var, ha_read_key_count),
11161 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11162 {"Handler_read_last",
11163 (char *)offsetof(System_status_var, ha_read_last_count),
11164 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11165 {"Handler_read_next",
11166 (char *)offsetof(System_status_var, ha_read_next_count),
11167 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11168 {"Handler_read_prev",
11169 (char *)offsetof(System_status_var, ha_read_prev_count),
11170 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11171 {"Handler_read_rnd", (char *)offsetof(System_status_var, ha_read_rnd_count),
11172 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11173 {"Handler_read_rnd_next",
11174 (char *)offsetof(System_status_var, ha_read_rnd_next_count),
11175 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11176 {"Handler_rollback", (char *)offsetof(System_status_var, ha_rollback_count),
11177 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11178 {"Handler_savepoint",
11179 (char *)offsetof(System_status_var, ha_savepoint_count),
11180 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11181 {"Handler_savepoint_rollback",
11182 (char *)offsetof(System_status_var, ha_savepoint_rollback_count),
11183 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11184 {"Handler_update", (char *)offsetof(System_status_var, ha_update_count),
11185 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11186 {"Handler_write", (char *)offsetof(System_status_var, ha_write_count),
11187 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11188 {"Key_blocks_not_flushed",
11189 (char *)offsetof(KEY_CACHE, global_blocks_changed), SHOW_KEY_CACHE_LONG,
11190 SHOW_SCOPE_GLOBAL},
11191 {"Key_blocks_unused", (char *)offsetof(KEY_CACHE, blocks_unused),
11192 SHOW_KEY_CACHE_LONG, SHOW_SCOPE_GLOBAL},
11193 {"Key_blocks_used", (char *)offsetof(KEY_CACHE, blocks_used),
11194 SHOW_KEY_CACHE_LONG, SHOW_SCOPE_GLOBAL},
11195 {"Key_read_requests", (char *)offsetof(KEY_CACHE, global_cache_r_requests),
11196 SHOW_KEY_CACHE_LONGLONG, SHOW_SCOPE_GLOBAL},
11197 {"Key_reads", (char *)offsetof(KEY_CACHE, global_cache_read),
11198 SHOW_KEY_CACHE_LONGLONG, SHOW_SCOPE_GLOBAL},
11199 {"Key_write_requests", (char *)offsetof(KEY_CACHE, global_cache_w_requests),
11200 SHOW_KEY_CACHE_LONGLONG, SHOW_SCOPE_GLOBAL},
11201 {"Key_writes", (char *)offsetof(KEY_CACHE, global_cache_write),
11202 SHOW_KEY_CACHE_LONGLONG, SHOW_SCOPE_GLOBAL},
11203 {"Last_query_cost", (char *)offsetof(System_status_var, last_query_cost),
11204 SHOW_DOUBLE_STATUS, SHOW_SCOPE_SESSION},
11205 {"Last_query_partial_plans",
11206 (char *)offsetof(System_status_var, last_query_partial_plans),
11207 SHOW_LONGLONG_STATUS, SHOW_SCOPE_SESSION},
11208 {"Locked_connects", (char *)&locked_account_connection_count, SHOW_LONG,
11209 SHOW_SCOPE_GLOBAL},
11210 {"Max_execution_time_exceeded",
11211 (char *)offsetof(System_status_var, max_execution_time_exceeded),
11212 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11213 {"Max_execution_time_set",
11214 (char *)offsetof(System_status_var, max_execution_time_set),
11215 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11216 {"Max_execution_time_set_failed",
11217 (char *)offsetof(System_status_var, max_execution_time_set_failed),
11218 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11219 {"Max_used_connections",
11220 (char *)&Connection_handler_manager::max_used_connections, SHOW_LONG,
11221 SHOW_SCOPE_GLOBAL},
11222 {"Max_used_connections_time", (char *)&show_max_used_connections_time,
11223 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
11224 {"Net_buffer_length",
11225 (char *)offsetof(System_status_var, net_buffer_length),
11226 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11227 {"Not_flushed_delayed_rows", (char *)&delayed_rows_in_use,
11228 SHOW_LONG_NOFLUSH, SHOW_SCOPE_GLOBAL},
11229 {"Open_files", (char *)&my_file_opened, SHOW_LONG_NOFLUSH,
11230 SHOW_SCOPE_GLOBAL},
11231 {"Open_streams", (char *)&my_stream_opened, SHOW_LONG_NOFLUSH,
11232 SHOW_SCOPE_GLOBAL},
11233 {"Open_table_definitions", (char *)&show_table_definitions, SHOW_FUNC,
11234 SHOW_SCOPE_GLOBAL},
11235 {"Open_tables", (char *)&show_open_tables, SHOW_FUNC, SHOW_SCOPE_ALL},
11236 {"Opened_files",
11237 const_cast<char *>(reinterpret_cast<const char *>(&my_file_total_opened)),
11238 SHOW_LONG_NOFLUSH, SHOW_SCOPE_GLOBAL},
11239 {"Opened_tables", (char *)offsetof(System_status_var, opened_tables),
11240 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11241 {"Opened_table_definitions",
11242 (char *)offsetof(System_status_var, opened_shares), SHOW_LONGLONG_STATUS,
11243 SHOW_SCOPE_ALL},
11244 {"Prepared_stmt_count", (char *)&show_prepared_stmt_count, SHOW_FUNC,
11245 SHOW_SCOPE_GLOBAL},
11246 {"Replica_open_temp_tables", (char *)&show_replica_open_temp_tables,
11247 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
11248 #ifndef NDEBUG
11249 {"Replica_rows_last_search_algorithm_used",
11250 (char *)&show_replica_rows_last_search_algorithm_used, SHOW_FUNC,
11251 SHOW_SCOPE_GLOBAL},
11252 #endif
11253 {"Queries", (char *)&show_queries, SHOW_FUNC, SHOW_SCOPE_ALL},
11254 {"Questions", (char *)offsetof(System_status_var, questions),
11255 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11256 {"Secondary_engine_execution_count",
11257 (char *)offsetof(System_status_var, secondary_engine_execution_count),
11258 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11259 {"Select_full_join",
11260 (char *)offsetof(System_status_var, select_full_join_count),
11261 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11262 {"Select_full_range_join",
11263 (char *)offsetof(System_status_var, select_full_range_join_count),
11264 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11265 {"Select_range", (char *)offsetof(System_status_var, select_range_count),
11266 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11267 {"Select_range_check",
11268 (char *)offsetof(System_status_var, select_range_check_count),
11269 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11270 {"Select_scan", (char *)offsetof(System_status_var, select_scan_count),
11271 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11272 {"Slave_open_temp_tables", (char *)&show_replica_open_temp_tables,
11273 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
11274 #ifndef NDEBUG
11275 {"Slave_rows_last_search_algorithm_used",
11276 (char *)&show_replica_rows_last_search_algorithm_used, SHOW_FUNC,
11277 SHOW_SCOPE_GLOBAL},
11278 #endif
11279 {"Slow_launch_threads",
11280 (char *)&Per_thread_connection_handler::slow_launch_threads, SHOW_LONG,
11281 SHOW_SCOPE_ALL},
11282 {"Slow_queries", (char *)offsetof(System_status_var, long_query_count),
11283 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11284 {"Sort_merge_passes",
11285 (char *)offsetof(System_status_var, filesort_merge_passes),
11286 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11287 {"Sort_range", (char *)offsetof(System_status_var, filesort_range_count),
11288 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11289 {"Sort_rows", (char *)offsetof(System_status_var, filesort_rows),
11290 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11291 {"Sort_scan", (char *)offsetof(System_status_var, filesort_scan_count),
11292 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11293 {"Ssl_accept_renegotiates",
11294 (char *)&Ssl_mysql_main_status::show_ssl_ctx_sess_accept_renegotiate,
11295 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
11296 {"Ssl_accepts", (char *)&Ssl_mysql_main_status::show_ssl_ctx_sess_accept,
11297 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
11298 {"Ssl_callback_cache_hits",
11299 (char *)&Ssl_mysql_main_status::show_ssl_ctx_sess_cb_hits, SHOW_FUNC,
11300 SHOW_SCOPE_GLOBAL},
11301 {"Ssl_cipher", (char *)&show_ssl_get_cipher, SHOW_FUNC, SHOW_SCOPE_ALL},
11302 {"Ssl_cipher_list", (char *)&show_ssl_get_cipher_list, SHOW_FUNC,
11303 SHOW_SCOPE_ALL},
11304 {"Ssl_client_connects",
11305 (char *)&Ssl_mysql_main_status::show_ssl_ctx_sess_connect, SHOW_FUNC,
11306 SHOW_SCOPE_GLOBAL},
11307 {"Ssl_connect_renegotiates",
11308 (char *)&Ssl_mysql_main_status::show_ssl_ctx_sess_connect_renegotiate,
11309 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
11310 {"Ssl_ctx_verify_depth",
11311 (char *)&Ssl_mysql_main_status::show_ssl_ctx_get_verify_depth, SHOW_FUNC,
11312 SHOW_SCOPE_GLOBAL},
11313 {"Ssl_ctx_verify_mode",
11314 (char *)&Ssl_mysql_main_status::show_ssl_ctx_get_verify_mode, SHOW_FUNC,
11315 SHOW_SCOPE_GLOBAL},
11316 {"Ssl_default_timeout", (char *)&show_ssl_get_default_timeout, SHOW_FUNC,
11317 SHOW_SCOPE_ALL},
11318 {"Ssl_finished_accepts",
11319 (char *)&Ssl_mysql_main_status::show_ssl_ctx_sess_accept_good, SHOW_FUNC,
11320 SHOW_SCOPE_GLOBAL},
11321 {"Ssl_finished_connects",
11322 (char *)&Ssl_mysql_main_status::show_ssl_ctx_sess_connect_good, SHOW_FUNC,
11323 SHOW_SCOPE_GLOBAL},
11324 {"Ssl_session_cache_hits",
11325 (char *)&Ssl_mysql_main_status::show_ssl_ctx_sess_hits, SHOW_FUNC,
11326 SHOW_SCOPE_GLOBAL},
11327 {"Ssl_session_cache_misses",
11328 (char *)&Ssl_mysql_main_status::show_ssl_ctx_sess_misses, SHOW_FUNC,
11329 SHOW_SCOPE_GLOBAL},
11330 {"Ssl_session_cache_mode",
11331 (char *)&Ssl_mysql_main_status::show_ssl_ctx_get_session_cache_mode,
11332 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
11333 {"Ssl_session_cache_overflows",
11334 (char *)&Ssl_mysql_main_status::show_ssl_ctx_sess_cache_full, SHOW_FUNC,
11335 SHOW_SCOPE_GLOBAL},
11336 {"Ssl_session_cache_size",
11337 (char *)&Ssl_mysql_main_status::show_ssl_ctx_sess_get_cache_size,
11338 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
11339 {"Ssl_session_cache_timeouts",
11340 (char *)&Ssl_mysql_main_status::show_ssl_ctx_sess_timeouts, SHOW_FUNC,
11341 SHOW_SCOPE_GLOBAL},
11342 {"Ssl_sessions_reused", (char *)&show_ssl_session_reused, SHOW_FUNC,
11343 SHOW_SCOPE_ALL},
11344 {"Ssl_used_session_cache_entries",
11345 (char *)&Ssl_mysql_main_status::show_ssl_ctx_sess_number, SHOW_FUNC,
11346 SHOW_SCOPE_GLOBAL},
11347 {"Ssl_verify_depth", (char *)&show_ssl_get_verify_depth, SHOW_FUNC,
11348 SHOW_SCOPE_ALL},
11349 {"Ssl_verify_mode", (char *)&show_ssl_get_verify_mode, SHOW_FUNC,
11350 SHOW_SCOPE_ALL},
11351 {"Ssl_version", (char *)&show_ssl_get_version, SHOW_FUNC, SHOW_SCOPE_ALL},
11352 {"Ssl_server_not_before",
11353 (char *)&Ssl_mysql_main_status::show_ssl_get_server_not_before, SHOW_FUNC,
11354 SHOW_SCOPE_ALL},
11355 {"Ssl_server_not_after",
11356 (char *)&Ssl_mysql_main_status::show_ssl_get_server_not_after, SHOW_FUNC,
11357 SHOW_SCOPE_ALL},
11358 {"Current_tls_ca", (char *)&Ssl_mysql_main_status::show_ssl_get_ssl_ca,
11359 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
11360 {"Current_tls_capath",
11361 (char *)&Ssl_mysql_main_status::show_ssl_get_ssl_capath, SHOW_FUNC,
11362 SHOW_SCOPE_GLOBAL},
11363 {"Current_tls_cert", (char *)&Ssl_mysql_main_status::show_ssl_get_ssl_cert,
11364 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
11365 {"Current_tls_key", (char *)&Ssl_mysql_main_status::show_ssl_get_ssl_key,
11366 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
11367 {"Current_tls_version",
11368 (char *)&Ssl_mysql_main_status::show_ssl_get_tls_version, SHOW_FUNC,
11369 SHOW_SCOPE_GLOBAL},
11370 {"Current_tls_cipher",
11371 (char *)&Ssl_mysql_main_status::show_ssl_get_ssl_cipher, SHOW_FUNC,
11372 SHOW_SCOPE_GLOBAL},
11373 {"Current_tls_ciphersuites",
11374 (char *)&Ssl_mysql_main_status::show_ssl_get_tls_ciphersuites, SHOW_FUNC,
11375 SHOW_SCOPE_GLOBAL},
11376 {"Current_tls_crl", (char *)&Ssl_mysql_main_status::show_ssl_get_ssl_crl,
11377 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
11378 {"Current_tls_crlpath",
11379 (char *)&Ssl_mysql_main_status::show_ssl_get_ssl_crlpath, SHOW_FUNC,
11380 SHOW_SCOPE_GLOBAL},
11381 {"Rsa_public_key", (char *)&show_rsa_public_key, SHOW_FUNC,
11382 SHOW_SCOPE_GLOBAL},
11383 {"Table_locks_immediate", (char *)&locks_immediate, SHOW_LONG,
11384 SHOW_SCOPE_GLOBAL},
11385 {"Table_locks_waited", (char *)&locks_waited, SHOW_LONG, SHOW_SCOPE_GLOBAL},
11386 {"Table_open_cache_hits",
11387 (char *)offsetof(System_status_var, table_open_cache_hits),
11388 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11389 {"Table_open_cache_misses",
11390 (char *)offsetof(System_status_var, table_open_cache_misses),
11391 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11392 {"Table_open_cache_overflows",
11393 (char *)offsetof(System_status_var, table_open_cache_overflows),
11394 SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
11395 {"Tc_log_max_pages_used", (char *)&tc_log_max_pages_used, SHOW_LONG,
11396 SHOW_SCOPE_GLOBAL},
11397 {"Tc_log_page_size", (char *)&tc_log_page_size, SHOW_LONG_NOFLUSH,
11398 SHOW_SCOPE_GLOBAL},
11399 {"Tc_log_page_waits", (char *)&tc_log_page_waits, SHOW_LONG,
11400 SHOW_SCOPE_GLOBAL},
11401 #ifdef HAVE_POOL_OF_THREADS
11402 {"Threadpool_idle_threads", (char *)&show_threadpool_idle_threads,
11403 SHOW_FUNC, SHOW_SCOPE_GLOBAL},
11404 {"Threadpool_threads", (char *)&tp_stats.num_worker_threads, SHOW_INT,
11405 SHOW_SCOPE_GLOBAL},
11406 #endif
11407 {"Threads_cached",
11408 (char *)&Per_thread_connection_handler::blocked_pthread_count,
11409 SHOW_LONG_NOFLUSH, SHOW_SCOPE_GLOBAL},
11410 {"Threads_connected", (char *)&Connection_handler_manager::connection_count,
11411 SHOW_INT, SHOW_SCOPE_GLOBAL},
11412 {"Threads_created", (char *)&show_num_thread_created, SHOW_FUNC,
11413 SHOW_SCOPE_GLOBAL},
11414 {"Threads_running", (char *)&show_num_thread_running, SHOW_FUNC,
11415 SHOW_SCOPE_GLOBAL},
11416 {"Uptime", (char *)&show_starttime, SHOW_FUNC, SHOW_SCOPE_GLOBAL},
11417 #ifdef ENABLED_PROFILING
11418 {"Uptime_since_flush_status", (char *)&show_flushstatustime, SHOW_FUNC,
11419 SHOW_SCOPE_GLOBAL},
11420 #endif
11421 {"Ssl_session_cache_timeout",
11422 (char *)&Ssl_mysql_main_status::show_ssl_ctx_sess_timeout, SHOW_FUNC,
11423 SHOW_SCOPE_GLOBAL},
11424 {"Tls_library_version", (char *)&show_tls_library_version, SHOW_FUNC,
11425 SHOW_SCOPE_GLOBAL},
11426 #ifdef WITH_WSREP
11427 {"wsrep_connected", (char *)&wsrep_connected, SHOW_BOOL, SHOW_SCOPE_GLOBAL},
11428 {"wsrep_ready", (char *)&wsrep_show_ready, SHOW_FUNC, SHOW_SCOPE_GLOBAL},
11429 {"wsrep_cluster_state_uuid", (char *)&wsrep_cluster_state_uuid,
11430 SHOW_CHAR_PTR, SHOW_SCOPE_GLOBAL},
11431 {"wsrep_cluster_conf_id", (char *)&wsrep_cluster_conf_id, SHOW_LONGLONG,
11432 SHOW_SCOPE_GLOBAL},
11433 {"wsrep_cluster_status", (char *)&wsrep_cluster_status, SHOW_CHAR_PTR,
11434 SHOW_SCOPE_GLOBAL},
11435 {"wsrep_cluster_size", (char *)&wsrep_cluster_size, SHOW_LONG_NOFLUSH,
11436 SHOW_SCOPE_GLOBAL},
11437 {"wsrep_local_index", (char *)&wsrep_local_index, SHOW_LONG_NOFLUSH,
11438 SHOW_SCOPE_GLOBAL},
11439 {"wsrep_local_bf_aborts", (char *)&wsrep_show_bf_aborts, SHOW_FUNC,
11440 SHOW_SCOPE_GLOBAL},
11441 {"wsrep_provider_name", (char *)&wsrep_provider_name, SHOW_CHAR_PTR,
11442 SHOW_SCOPE_GLOBAL},
11443 {"wsrep_provider_version", (char *)&wsrep_provider_version, SHOW_CHAR_PTR,
11444 SHOW_SCOPE_GLOBAL},
11445 {"wsrep_provider_vendor", (char *)&wsrep_provider_vendor, SHOW_CHAR_PTR,
11446 SHOW_SCOPE_GLOBAL},
11447 {"wsrep_provider_capabilities", (char *)&wsrep_provider_capabilities,
11448 SHOW_CHAR_PTR, SHOW_SCOPE_GLOBAL},
11449 {"wsrep_thread_count", (char *)&wsrep_running_threads, SHOW_LONG_NOFLUSH,
11450 SHOW_SCOPE_GLOBAL},
11451 {"wsrep_cluster_capabilities", (char *)&wsrep_cluster_capabilities,
11452 SHOW_CHAR_PTR, SHOW_SCOPE_GLOBAL},
11453 {"wsrep", (char *)&wsrep_show_status, SHOW_FUNC, SHOW_SCOPE_ALL},
11454 #endif /* WITH_WSREP */
11455 {NullS, NullS, SHOW_LONG, SHOW_SCOPE_ALL}};
11456
11457 30086 void add_terminator(vector<my_option> *options) {
11458 30086 my_option empty_element = {nullptr, 0, nullptr, nullptr, nullptr,
11459 nullptr, GET_NO_ARG, NO_ARG, 0, 0,
11460 0, nullptr, 0, nullptr};
11461
1/2
✓ Branch 0 taken 30086 times.
✗ Branch 1 not taken.
30086 options->push_back(empty_element);
11462 30086 }
11463
11464 325 static void print_server_version(void) {
11465 325 set_server_version();
11466
11467 325 print_explicit_version(server_version);
11468 325 }
11469
11470 /** Compares two options' names, treats - and _ the same */
11471 126813 static bool operator<(const my_option &a, const my_option &b) {
11472 126813 const char *sa = a.name;
11473 126813 const char *sb = b.name;
11474
4/4
✓ Branch 0 taken 691143 times.
✓ Branch 1 taken 921 times.
✓ Branch 2 taken 880 times.
✓ Branch 3 taken 41 times.
692064 for (; *sa || *sb; sa++, sb++) {
11475
2/2
✓ Branch 0 taken 78854 times.
✓ Branch 1 taken 613169 times.
692023 if (*sa < *sb) {
11476
4/4
✓ Branch 0 taken 1892 times.
✓ Branch 1 taken 76962 times.
✓ Branch 2 taken 1547 times.
✓ Branch 3 taken 345 times.
78854 if (*sa == '-' && *sb == '_')
11477 1547 continue;
11478 else
11479 77307 return true;
11480 }
11481
2/2
✓ Branch 0 taken 50959 times.
✓ Branch 1 taken 562210 times.
613169 if (*sa > *sb) {
11482
4/4
✓ Branch 0 taken 1817 times.
✓ Branch 1 taken 49142 times.
✓ Branch 2 taken 1494 times.
✓ Branch 3 taken 323 times.
50959 if (*sa == '_' && *sb == '-')
11483 1494 continue;
11484 else
11485 49465 return false;
11486 }
11487 }
11488
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
41 assert(a.name == b.name);
11489 41 return false;
11490 }
11491
11492 14 static void print_help() {
11493 14 MEM_ROOT mem_root(key_memory_help, 4096);
11494
11495 14 all_options.pop_back();
11496
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 sys_var_add_options(&all_options, sys_var::PARSE_EARLY);
11497
2/2
✓ Branch 0 taken 322 times.
✓ Branch 1 taken 14 times.
336 for (my_option *opt = my_long_early_options; opt->name != nullptr; opt++) {
11498
1/2
✓ Branch 0 taken 322 times.
✗ Branch 1 not taken.
322 all_options.push_back(*opt);
11499 }
11500
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 add_plugin_options(&all_options, &mem_root);
11501
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 std::sort(all_options.begin(), all_options.end(), std::less<my_option>());
11502
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 add_terminator(&all_options);
11503
11504
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 my_print_help(&all_options[0]);
11505
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 my_print_variables(&all_options[0]);
11506
11507
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 mem_root.Clear();
11508 14 vector<my_option>().swap(all_options); // Deletes the vector contents.
11509 14 }
11510
11511 14 static void usage(void) {
11512
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 DBUG_TRACE;
11513
2/4
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 14 times.
14 if (!(default_charset_info = get_charset_by_csname(
11514 default_character_set_name, MY_CS_PRIMARY, MYF(MY_WME))))
11515 exit(MYSQLD_ABORT_EXIT);
11516
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if (!default_collation_name)
11517 default_collation_name = default_charset_info->m_coll_name;
11518
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 14 times.
✗ Branch 5 not taken.
14 if (is_help_or_validate_option() || opt_verbose) {
11519
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 my_progname = my_progname + dirname_length(my_progname);
11520 }
11521
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 print_server_version();
11522
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 puts(ORACLE_WELCOME_COPYRIGHT_NOTICE("2000"));
11523
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 puts("Starts the MySQL database server.\n");
11524
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 printf("Usage: %s [OPTIONS]\n", my_progname);
11525
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if (!opt_verbose)
11526 puts(
11527 "\nFor more help options (several pages), use mysqld --verbose "
11528 "--help.");
11529 else {
11530 #ifdef _WIN32
11531 puts(
11532 "NT and Win32 specific options:\n\
11533 --install Install the default service (NT).\n\
11534 --install-manual Install the default service started manually (NT).\n\
11535 --install service_name Install an optional service (NT).\n\
11536 --install-manual service_name Install an optional service started manually (NT).\n\
11537 --remove Remove the default service from the service list (NT).\n\
11538 --remove service_name Remove the service_name from the service list (NT).\n\
11539 --enable-named-pipe Only to be used for the default server (NT).\n\
11540 --standalone Dummy option to start as a standalone server (NT).\
11541 ");
11542 puts("");
11543 #endif
11544
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 print_defaults(MYSQL_CONFIG_NAME, load_default_groups);
11545
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 puts("");
11546
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 set_ports();
11547
11548 /* Print out all the options including plugin supplied options */
11549
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 print_help();
11550
11551
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 13 times.
14 if (!dynamic_plugins_are_initialized) {
11552
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 puts(
11553 "\n\
11554 Plugins have parameters that are not reflected in this list\n\
11555 because execution stopped before plugins were initialized.");
11556 }
11557
11558
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 puts(
11559 "\n\
11560 To see what values a running MySQL server is using, type\n\
11561 'mysqladmin variables' instead of 'mysqld --verbose --help'.");
11562 }
11563 14 }
11564
11565 /**
11566 Initialize MySQL global variables to default values.
11567
11568 @note
11569 The reason to set a lot of global variables to zero is that
11570 on some exotic platforms global variables are
11571 not set to 0 when a program starts.
11572
11573 We don't need to set variables referred to in my_long_options
11574 as these are initialized by my_getopt.
11575 */
11576
11577 9824 static int mysql_init_variables() {
11578 /* Things reset to zero */
11579 9824 opt_skip_replica_start = false;
11580 9824 pidfile_name[0] = 0;
11581 9824 myisam_test_invalid_symlink = test_if_data_home_dir;
11582 9824 opt_general_log = opt_slow_log = false;
11583 9824 opt_disable_networking = opt_skip_show_db = false;
11584 9824 opt_skip_name_resolve = false;
11585 9824 opt_general_logname = opt_binlog_index_name = opt_slow_logname = nullptr;
11586 9824 opt_tc_log_file = "tc.log"; // no hostname in tc_log file name !
11587 9824 opt_myisam_log = false;
11588 9824 mqh_used = false;
11589 9824 cleanup_done = 0;
11590 9824 server_id_supplied = false;
11591 9824 select_errors = ha_open_options = 0;
11592 9824 atomic_replica_open_temp_tables = 0;
11593 9824 opt_endinfo = using_udf_functions = false;
11594 9824 opt_using_transactions = false;
11595 9824 set_connection_events_loop_aborted(false);
11596 9824 set_mysqld_offline_mode(false);
11597 9824 set_mysqld_partial_revokes(opt_partial_revokes);
11598 9824 server_operational_state = SERVER_BOOTING;
11599 9824 aborted_threads = 0;
11600 9824 delayed_insert_threads = delayed_insert_writes = delayed_rows_in_use = 0;
11601 9824 delayed_insert_errors = 0;
11602 9824 specialflag = 0;
11603 9824 binlog_cache_use = binlog_cache_disk_use = 0;
11604 9824 mysqld_user = mysqld_chroot = opt_init_file = opt_bin_logname = nullptr;
11605 9824 prepared_stmt_count = 0;
11606 9824 mysqld_unix_port = opt_mysql_tmpdir = my_bind_addr_str = NullS;
11607 9824 new (&mysql_tmpdir_list) MY_TMPDIR;
11608 9824 memset(&global_status_var, 0, sizeof(global_status_var));
11609 9824 opt_large_pages = false;
11610 9824 opt_super_large_pages = false;
11611 #if defined(ENABLED_DEBUG_SYNC)
11612 9824 opt_debug_sync_timeout = 0;
11613 #endif /* defined(ENABLED_DEBUG_SYNC) */
11614 9824 server_uuid[0] = 0;
11615
11616 /* Character sets */
11617 9824 system_charset_info = &my_charset_utf8_general_ci;
11618 9824 files_charset_info = &my_charset_utf8_general_ci;
11619 9824 national_charset_info = &my_charset_utf8_general_ci;
11620 9824 table_alias_charset = &my_charset_bin;
11621 9824 character_set_filesystem = &my_charset_bin;
11622
11623 9824 opt_specialflag = 0;
11624 9824 pidfile_name_ptr = pidfile_name;
11625 9824 lc_messages_dir_ptr = lc_messages_dir;
11626 9824 protocol_version = PROTOCOL_VERSION;
11627 9824 what_to_log = ~(1L << (uint)COM_TIME);
11628 9824 refresh_version = 1L; /* Increments on each reload */
11629 9824 my_stpcpy(server_version, MYSQL_SERVER_VERSION);
11630 9824 key_caches.clear();
11631
2/4
✓ Branch 0 taken 9824 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9824 times.
9824 if (!(dflt_key_cache = get_or_create_key_cache(std::string_view{
11632 9824 default_key_cache_base.str, default_key_cache_base.length}))) {
11633 LogErr(ERROR_LEVEL, ER_KEYCACHE_OOM);
11634 return 1;
11635 }
11636 /* set key_cache_hash.default_value = dflt_key_cache */
11637 9824 multi_keycache_init();
11638
11639 /* Replication parameters */
11640 9824 master_info_file = "master.info";
11641 9824 relay_log_info_file = "relay-log.info";
11642 9824 report_user = report_password = report_host = nullptr; /* TO BE DELETED */
11643 9824 opt_relay_logname = opt_relaylog_index_name = nullptr;
11644 9824 opt_relaylog_index_name_supplied = false;
11645 9824 opt_relay_logname_supplied = false;
11646 9824 log_bin_basename = nullptr;
11647 9824 log_bin_index = nullptr;
11648
11649 /* Handler variables */
11650 9824 total_ha_2pc = 0;
11651 /* Variables in libraries */
11652 9824 charsets_dir = nullptr;
11653 9824 default_character_set_name = MYSQL_DEFAULT_CHARSET_NAME;
11654 9824 default_collation_name = compiled_default_collation_name;
11655 9824 character_set_filesystem_name = "binary";
11656 9824 lc_messages = mysqld_default_locale_name;
11657 9824 lc_time_names_name = mysqld_default_locale_name;
11658 9824 opt_replication_optimize_for_static_plugin_config = false;
11659 9824 opt_replication_sender_observe_commit_only = false;
11660
11661 /* Variables that depends on compile options */
11662 #ifndef NDEBUG
11663 9824 default_dbug_option =
11664 IF_WIN("d:t:i:O,\\mysqld.trace", "d:t:i:o,/tmp/mysqld.trace");
11665 #endif
11666 #ifdef ENABLED_PROFILING
11667 9824 have_profiling = SHOW_OPTION_YES;
11668 #else
11669 have_profiling = SHOW_OPTION_NO;
11670 #endif
11671
11672 9824 have_symlink = SHOW_OPTION_YES;
11673
11674 9824 have_dlopen = SHOW_OPTION_YES;
11675
11676 9824 have_query_cache = SHOW_OPTION_NO;
11677
11678 9824 have_geometry = SHOW_OPTION_YES;
11679
11680 9824 have_rtree_keys = SHOW_OPTION_YES;
11681
11682 /* Always true */
11683 9824 have_compress = SHOW_OPTION_YES;
11684 #if defined(_WIN32)
11685 shared_memory_base_name = default_shared_memory_base_name;
11686 #endif
11687
11688 9824 have_backup_locks = SHOW_OPTION_YES;
11689 9824 have_backup_safe_binlog_info = SHOW_OPTION_YES;
11690 9824 have_snapshot_cloning = SHOW_OPTION_YES;
11691
11692 #ifdef WITH_WSREP
11693
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9824 times.
9824 if (wsrep_init_vars()) return 1;
11694 #endif /* WITH_WSREP */
11695
11696 9824 return 0;
11697 }
11698
11699 /**
11700 Check if it is a global replication filter setting.
11701
11702 @param argument The setting of startup option --replicate-*.
11703
11704 @retval
11705 0 OK
11706 @retval
11707 1 Error
11708 */
11709 356 static bool is_rpl_global_filter_setting(char *argument) {
11710
1/2
✓ Branch 0 taken 356 times.
✗ Branch 1 not taken.
356 DBUG_TRACE;
11711
11712 356 bool res = false;
11713 356 char *p = strchr(argument, ':');
11714
2/2
✓ Branch 0 taken 260 times.
✓ Branch 1 taken 96 times.
356 if (p == nullptr) res = true;
11715
11716 356 return res;
11717 356 }
11718
11719 /**
11720 Extract channel name and filter value from argument.
11721
11722 @param [out] channel_name The name of the channel.
11723 @param [out] filter_val The value of filter.
11724 @param argument The setting of startup option --replicate-*.
11725 */
11726 96 void parse_filter_arg(char **channel_name, char **filter_val, char *argument) {
11727
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 DBUG_TRACE;
11728
11729 96 char *p = strchr(argument, ':');
11730
11731
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
96 assert(p != nullptr);
11732
11733 /*
11734 If argument='channel_1:db1', then channel_name='channel_1'
11735 and filter_val='db1'; If argument=':db1', then channel_name=''
11736 and filter_val='db1'.
11737 */
11738 96 *channel_name = argument;
11739 96 *filter_val = p + 1;
11740 96 *p = 0;
11741 96 }
11742
11743 /**
11744 Extract channel name and filter value from argument.
11745
11746 @param [out] key The db is rewritten from.
11747 @param [out] val The db is rewritten to.
11748 @param argument The value of filter.
11749
11750 @retval
11751 0 OK
11752 @retval
11753 1 Error
11754 */
11755 54 static int parse_replicate_rewrite_db(char **key, char **val, char *argument) {
11756
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 DBUG_TRACE;
11757 char *p;
11758 54 *key = argument;
11759
11760
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 46 times.
54 if (!(p = strstr(argument, "->"))) {
11761
8/16
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 8 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 8 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 8 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 8 times.
✗ Branch 15 not taken.
8 LogErr(ERROR_LEVEL, ER_RPL_REWRITEDB_MISSING_ARROW);
11762 8 return 1;
11763 }
11764 46 *val = p + 2;
11765
11766
3/4
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 44 times.
46 while (p > argument && my_isspace(mysqld_charset, p[-1])) p--;
11767 46 *p = 0;
11768
11769
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 44 times.
46 if (!**key) {
11770
8/16
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 2 times.
✗ Branch 15 not taken.
2 LogErr(ERROR_LEVEL, ER_RPL_REWRITEDB_EMPTY_FROM);
11771 2 return 1;
11772 }
11773
4/4
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 39 times.
47 while (**val && my_isspace(mysqld_charset, **val)) (*val)++;
11774
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 39 times.
44 if (!**val) {
11775
8/16
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 5 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 5 times.
✗ Branch 15 not taken.
5 LogErr(ERROR_LEVEL, ER_RPL_REWRITEDB_EMPTY_TO);
11776 5 return 1;
11777 }
11778
11779 39 return 0;
11780 54 }
11781
11782 630137 bool mysqld_get_one_option(int optid,
11783 const struct my_option *opt [[maybe_unused]],
11784 char *argument) {
11785 630137 Rpl_filter *rpl_filter = nullptr;
11786 char *filter_val;
11787 char *channel_name;
11788
11789
1/2
✓ Branch 0 taken 630137 times.
✗ Branch 1 not taken.
630137 auto *sysvar = intern_find_sys_var(opt->name, strlen(opt->name));
11790
4/4
✓ Branch 0 taken 442776 times.
✓ Branch 1 taken 187361 times.
✓ Branch 2 taken 7938 times.
✓ Branch 3 taken 434838 times.
630137 if (sysvar && sysvar->m_persisted_alias &&
11791
2/2
✓ Branch 0 taken 604 times.
✓ Branch 1 taken 7334 times.
7938 sysvar->m_is_persisted_deprecated) {
11792 /*
11793 At this point, my_handle_options (through setval and
11794 setval_source) has set the source for itself. It was set using
11795 direct access to the my_option object, so it is really the
11796 source object that is a member of this sysvar that has been set.
11797 In case this is a deprecated alias, that does not help, because
11798 the high-level getters and setters will get and set the value in
11799 the base variable, not the alias. Therefore, we copy the source
11800 from the alias to the base variable, using a low-level getter in
11801 the alias and a high-level setter in the alias.
11802 */
11803 604 auto *source = sysvar->get_option()->arg_source;
11804
1/2
✓ Branch 0 taken 604 times.
✗ Branch 1 not taken.
604 sysvar->set_source(source->m_source);
11805
1/2
✓ Branch 0 taken 604 times.
✗ Branch 1 not taken.
604 sysvar->set_source_name(source->m_path_name);
11806
2/2
✓ Branch 0 taken 565 times.
✓ Branch 1 taken 39 times.
604 if (source->m_source != PERSISTED) {
11807 /*
11808 Generate the deprecation warning. But not if we are loading
11809 it from the persisted variables file (i.e., this is a variable
11810 having the PERSIST_AS_READONLY flag set): in that case a more
11811 specific warning was already generated when loading the
11812 persisted variable.
11813 */
11814 565 const char *ds = sysvar->get_deprecation_substitute();
11815
2/4
✓ Branch 0 taken 565 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 565 times.
✗ Branch 3 not taken.
565 if (ds) push_deprecated_warn(nullptr, opt->name, ds);
11816 }
11817 }
11818
11819
64/75
✓ Branch 0 taken 269 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 540 times.
✓ Branch 3 taken 33 times.
✓ Branch 4 taken 10667 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 189 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 3774 times.
✓ Branch 11 taken 2 times.
✓ Branch 12 taken 22 times.
✓ Branch 13 taken 22 times.
✓ Branch 14 taken 28431 times.
✓ Branch 15 taken 29 times.
✓ Branch 16 taken 4 times.
✓ Branch 17 taken 135 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 311 times.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 4926 times.
✓ Branch 24 taken 12 times.
✓ Branch 25 taken 35 times.
✓ Branch 26 taken 69 times.
✓ Branch 27 taken 54 times.
✓ Branch 28 taken 19 times.
✓ Branch 29 taken 9 times.
✓ Branch 30 taken 43 times.
✓ Branch 31 taken 41 times.
✓ Branch 32 taken 43 times.
✓ Branch 33 taken 71 times.
✓ Branch 34 taken 3037 times.
✗ Branch 35 not taken.
✓ Branch 36 taken 1 times.
✓ Branch 37 taken 41 times.
✓ Branch 38 taken 8995 times.
✓ Branch 39 taken 10 times.
✓ Branch 40 taken 18 times.
✓ Branch 41 taken 9905 times.
✓ Branch 42 taken 175 times.
✓ Branch 43 taken 8913 times.
✓ Branch 44 taken 1137 times.
✓ Branch 45 taken 513 times.
✓ Branch 46 taken 1684 times.
✓ Branch 47 taken 6 times.
✓ Branch 48 taken 9468 times.
✓ Branch 49 taken 2 times.
✓ Branch 50 taken 2 times.
✓ Branch 51 taken 2 times.
✓ Branch 52 taken 7 times.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✓ Branch 57 taken 482 times.
✓ Branch 58 taken 139 times.
✓ Branch 59 taken 2782 times.
✗ Branch 60 not taken.
✓ Branch 61 taken 4 times.
✓ Branch 62 taken 5 times.
✓ Branch 63 taken 4 times.
✓ Branch 64 taken 1 times.
✓ Branch 65 taken 108 times.
✓ Branch 66 taken 74 times.
✓ Branch 67 taken 276 times.
✓ Branch 68 taken 95 times.
✓ Branch 69 taken 1 times.
✓ Branch 70 taken 1 times.
✓ Branch 71 taken 106 times.
✓ Branch 72 taken 166 times.
✓ Branch 73 taken 1 times.
✓ Branch 74 taken 532219 times.
630137 switch (optid) {
11820 269 case '#':
11821 #ifndef NDEBUG
11822
2/4
✓ Branch 0 taken 269 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 269 times.
✗ Branch 3 not taken.
269 DBUG_SET_INITIAL(argument ? argument : default_dbug_option);
11823 #endif
11824 269 opt_endinfo = true; /* unireg: memory allocation */
11825 269 break;
11826 2 case 'a':
11827 2 global_system_variables.sql_mode = MODE_ANSI;
11828 2 global_system_variables.transaction_isolation = ISO_SERIALIZABLE;
11829 2 break;
11830 540 case 'b':
11831
1/2
✓ Branch 0 taken 540 times.
✗ Branch 1 not taken.
540 strmake(mysql_home, argument, sizeof(mysql_home) - 1);
11832 540 mysql_home_ptr = mysql_home;
11833 540 break;
11834 33 case 'C':
11835
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 1 times.
33 if (default_collation_name == compiled_default_collation_name)
11836 32 default_collation_name = nullptr;
11837 33 break;
11838 10667 case 'h':
11839
1/2
✓ Branch 0 taken 10667 times.
✗ Branch 1 not taken.
10667 strmake(mysql_real_data_home, argument, sizeof(mysql_real_data_home) - 1);
11840 /* Correct pointer set by my_getopt */
11841 10667 mysql_real_data_home_ptr = mysql_real_data_home;
11842 10667 break;
11843 case 'u':
11844 if (!mysqld_user || !strcmp(mysqld_user, argument))
11845 mysqld_user = argument;
11846 else
11847 LogErr(WARNING_LEVEL, ER_THE_USER_ABIDES, argument, mysqld_user);
11848 break;
11849 3 case 's':
11850
3/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
3 if (argument && argument[0] == '0') {
11851
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(WARNING_LEVEL, ER_DEPRECATE_MSG_NO_REPLACEMENT,
11852 "Disabling symbolic links using --skip-symbolic-links"
11853 " (or equivalent) is the default. Consider not using"
11854 " this option as it");
11855 } else {
11856
8/16
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 2 times.
✗ Branch 15 not taken.
2 LogErr(WARNING_LEVEL, ER_DEPRECATE_MSG_NO_REPLACEMENT,
11857 "Enabling symbolic using --symbolic-links/-s (or equivalent)");
11858 }
11859 3 break;
11860 case 'L':
11861 push_deprecated_warn(nullptr, "--language/-l", "'--lc-messages-dir'");
11862 [[fallthrough]];
11863 189 case OPT_LC_MESSAGES_DIRECTORY:
11864
1/2
✓ Branch 0 taken 189 times.
✗ Branch 1 not taken.
189 strmake(lc_messages_dir, argument, sizeof(lc_messages_dir) - 1);
11865 189 lc_messages_dir_ptr = lc_messages_dir;
11866 189 break;
11867 1 case OPT_SHOW_SLAVE_AUTH_INFO_DEPRECATED:
11868
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 push_deprecated_warn(nullptr, "show-slave-auth-info",
11869 "show-replica-auth-info");
11870 1 break;
11871 3774 case OPT_BINLOG_FORMAT:
11872 3774 binlog_format_used = true;
11873 3774 break;
11874 2 case OPT_BINLOG_MAX_FLUSH_QUEUE_TIME:
11875
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 push_deprecated_warn_no_replacement(nullptr,
11876 "--binlog_max_flush_queue_time");
11877 2 break;
11878 22 case OPT_EXPIRE_LOGS_DAYS:
11879
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 push_deprecated_warn(nullptr, "expire-logs-days",
11880 "binlog_expire_logs_seconds");
11881 22 expire_logs_days_supplied = true;
11882 22 break;
11883 22 case OPT_BINLOG_EXPIRE_LOGS_SECONDS:
11884 22 binlog_expire_logs_seconds_supplied = true;
11885 22 break;
11886 28431 case OPT_SSL_KEY:
11887 case OPT_SSL_CERT:
11888 case OPT_SSL_CA:
11889 case OPT_SSL_CAPATH:
11890 case OPT_SSL_CIPHER:
11891 case OPT_TLS_CIPHERSUITES:
11892 case OPT_SSL_CRL:
11893 case OPT_SSL_CRLPATH:
11894 /*
11895 Enable use of SSL if we are using any ssl option.
11896 One can disable SSL later by using --skip-ssl or --ssl=0.
11897 */
11898 28431 opt_use_ssl = true;
11899 28431 break;
11900 29 case OPT_TLS_VERSION:
11901 29 opt_use_ssl = true;
11902
2/4
✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 29 times.
29 if (validate_tls_version(argument)) {
11903 LogErr(ERROR_LEVEL, ER_INVALID_TLS_VERSION, argument);
11904 return true;
11905 }
11906 29 break;
11907 4 case OPT_USE_ADMIN_SSL:
11908
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
4 if (opt_use_admin_ssl)
11909
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 push_deprecated_warn_no_replacement(nullptr, "--admin-ssl=on");
11910 else
11911
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 push_deprecated_warn(nullptr, "--admin-ssl=off",
11912 "--admin-tls-version=invalid");
11913 4 break;
11914 135 case OPT_USE_SSL:
11915
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 129 times.
135 if (opt_use_ssl)
11916
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 push_deprecated_warn_no_replacement(nullptr, "--ssl=on");
11917 else
11918
1/2
✓ Branch 0 taken 129 times.
✗ Branch 1 not taken.
129 push_deprecated_warn(nullptr, "--ssl=off", "--tls-version=invalid");
11919 135 break;
11920 case OPT_ADMIN_SSL_KEY:
11921 case OPT_ADMIN_SSL_CERT:
11922 case OPT_ADMIN_SSL_CA:
11923 case OPT_ADMIN_SSL_CAPATH:
11924 case OPT_ADMIN_SSL_CIPHER:
11925 case OPT_ADMIN_TLS_CIPHERSUITES:
11926 case OPT_ADMIN_SSL_CRL:
11927 case OPT_ADMIN_SSL_CRLPATH:
11928 /*
11929 Enable use of SSL if we are using any ssl option.
11930 One can disable SSL later by using --skip-admin-ssl or --admin-ssl=0.
11931 */
11932 g_admin_ssl_configured = true;
11933 opt_use_admin_ssl = true;
11934 break;
11935 case OPT_ADMIN_TLS_VERSION:
11936 g_admin_ssl_configured = true;
11937 opt_use_admin_ssl = true;
11938 if (validate_tls_version(argument)) {
11939 LogErr(ERROR_LEVEL, ER_INVALID_TLS_VERSION, argument);
11940 return true;
11941 }
11942 break;
11943 311 case 'V':
11944
1/2
✓ Branch 0 taken 311 times.
✗ Branch 1 not taken.
311 print_server_version();
11945 311 exit(MYSQLD_SUCCESS_EXIT);
11946 1 case 'T':
11947
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 test_flags = argument ? (uint)atoi(argument) : 0;
11948 1 opt_endinfo = true;
11949 1 break;
11950 case (int)OPT_ISAM_LOG:
11951 opt_myisam_log = true;
11952 break;
11953 4926 case (int)OPT_BIN_LOG:
11954 4926 opt_bin_log = (argument != disabled_my_option);
11955
2/2
✓ Branch 0 taken 340 times.
✓ Branch 1 taken 4586 times.
4926 if (!opt_bin_log) {
11956 // Clear the binlog basename used by any previous --log-bin
11957
1/2
✓ Branch 0 taken 340 times.
✗ Branch 1 not taken.
340 if (opt_bin_logname) {
11958
1/2
✓ Branch 0 taken 340 times.
✗ Branch 1 not taken.
340 my_free(opt_bin_logname);
11959 340 opt_bin_logname = nullptr;
11960 }
11961 }
11962 4926 log_bin_supplied = true;
11963 4926 break;
11964 12 case (int)OPT_REPLICA_ENABLE_EVENT: {
11965
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 std::ostringstream message{};
11966
4/6
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 6 times.
12 if (Rpl_event_ctx::get_instance().process_argument(argument, message)) {
11967
9/18
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 6 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 6 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 6 times.
✗ Branch 17 not taken.
6 LogErr(ERROR_LEVEL, ER_RPL_ENABLE_EVENT_ADD_WILD_PATTERN_FAILED,
11968 argument, message.str().c_str());
11969 6 return true;
11970 }
11971 6 break;
11972
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 }
11973 35 case (int)OPT_REPLICATE_IGNORE_DB: {
11974
3/4
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23 times.
✓ Branch 3 taken 12 times.
35 if (is_rpl_global_filter_setting(argument)) {
11975
1/2
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
23 rpl_global_filter.add_ignore_db(argument);
11976
1/2
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
23 rpl_global_filter.ignore_db_statistics.set_all(
11977 CONFIGURED_BY_STARTUP_OPTIONS);
11978 } else {
11979
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 parse_filter_arg(&channel_name, &filter_val, argument);
11980 #ifdef WITH_WSREP
11981
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
12 if (wsrep_is_wsrep_channel_name(channel_name)) {
11982 WSREP_ERROR(
11983 "Configuration of the '%s' channel by replicate-ignore-db is not "
11984 "allowed.",
11985 WSREP_CHANNEL_NAME);
11986 return 1;
11987 }
11988 #endif /* WITH_WSREP */
11989
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 rpl_filter = rpl_channel_filters.get_channel_filter(channel_name);
11990
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 rpl_filter->add_ignore_db(filter_val);
11991
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 rpl_filter->ignore_db_statistics.set_all(
11992 CONFIGURED_BY_STARTUP_OPTIONS_FOR_CHANNEL);
11993 }
11994 35 break;
11995 }
11996 69 case (int)OPT_REPLICATE_DO_DB: {
11997
3/4
✓ Branch 0 taken 69 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 49 times.
✓ Branch 3 taken 20 times.
69 if (is_rpl_global_filter_setting(argument)) {
11998
1/2
✓ Branch 0 taken 49 times.
✗ Branch 1 not taken.
49 rpl_global_filter.add_do_db(argument);
11999
1/2
✓ Branch 0 taken 49 times.
✗ Branch 1 not taken.
49 rpl_global_filter.do_db_statistics.set_all(
12000 CONFIGURED_BY_STARTUP_OPTIONS);
12001 } else {
12002
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 parse_filter_arg(&channel_name, &filter_val, argument);
12003 #ifdef WITH_WSREP
12004
2/4
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20 times.
20 if (wsrep_is_wsrep_channel_name(channel_name)) {
12005 WSREP_ERROR(
12006 "Configuration of the '%s' channel by replicate-do-db is not "
12007 "allowed.",
12008 WSREP_CHANNEL_NAME);
12009 return 1;
12010 }
12011 #endif /* WITH_WSREP */
12012
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 rpl_filter = rpl_channel_filters.get_channel_filter(channel_name);
12013
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 rpl_filter->add_do_db(filter_val);
12014
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 rpl_filter->do_db_statistics.set_all(
12015 CONFIGURED_BY_STARTUP_OPTIONS_FOR_CHANNEL);
12016 }
12017 69 break;
12018 }
12019 54 case (int)OPT_REPLICATE_REWRITE_DB: {
12020 char *key, *val;
12021
3/4
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
✓ Branch 3 taken 14 times.
54 if (is_rpl_global_filter_setting(argument)) {
12022
3/4
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 28 times.
43 if (parse_replicate_rewrite_db(&key, &val, argument)) return true;
12023
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 rpl_global_filter.add_db_rewrite(key, val);
12024
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 rpl_global_filter.rewrite_db_statistics.set_all(
12025 CONFIGURED_BY_STARTUP_OPTIONS);
12026 } else {
12027
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 parse_filter_arg(&channel_name, &filter_val, argument);
12028 #ifdef WITH_WSREP
12029
2/4
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 14 times.
14 if (wsrep_is_wsrep_channel_name(channel_name)) {
12030 WSREP_ERROR(
12031 "Configuration of the '%s' channel by replicate-rewrite-db is "
12032 "not allowed.",
12033 WSREP_CHANNEL_NAME);
12034 return 1;
12035 }
12036 #endif /* WITH_WSREP */
12037
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 rpl_filter = rpl_channel_filters.get_channel_filter(channel_name);
12038
3/4
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 11 times.
14 if (parse_replicate_rewrite_db(&key, &val, filter_val)) return true;
12039
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 rpl_filter->add_db_rewrite(key, val);
12040
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 rpl_filter->rewrite_db_statistics.set_all(
12041 CONFIGURED_BY_STARTUP_OPTIONS_FOR_CHANNEL);
12042 }
12043 39 break;
12044 }
12045
12046 19 case (int)OPT_BINLOG_IGNORE_DB: {
12047
1/2
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
19 binlog_filter->add_ignore_db(argument);
12048 19 break;
12049 }
12050 9 case (int)OPT_BINLOG_DO_DB: {
12051
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 binlog_filter->add_do_db(argument);
12052 9 break;
12053 }
12054 43 case (int)OPT_REPLICATE_DO_TABLE: {
12055
3/4
✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 31 times.
✓ Branch 3 taken 12 times.
43 if (is_rpl_global_filter_setting(argument)) {
12056
3/4
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 30 times.
31 if (rpl_global_filter.add_do_table_array(argument)) {
12057
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(ERROR_LEVEL, ER_RPL_CANT_ADD_DO_TABLE, argument);
12058 1 return true;
12059 }
12060
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 rpl_global_filter.do_table_statistics.set_all(
12061 CONFIGURED_BY_STARTUP_OPTIONS);
12062 } else {
12063
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 parse_filter_arg(&channel_name, &filter_val, argument);
12064 #ifdef WITH_WSREP
12065
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
12 if (wsrep_is_wsrep_channel_name(channel_name)) {
12066 WSREP_ERROR(
12067 "Configuration of the '%s' channel by replicate-do-table is not "
12068 "allowed.",
12069 WSREP_CHANNEL_NAME);
12070 return 1;
12071 }
12072 #endif /* WITH_WSREP */
12073
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 rpl_filter = rpl_channel_filters.get_channel_filter(channel_name);
12074
3/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 11 times.
12 if (rpl_filter->add_do_table_array(filter_val)) {
12075
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(ERROR_LEVEL, ER_RPL_CANT_ADD_DO_TABLE, argument);
12076 1 return true;
12077 }
12078
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 rpl_filter->do_table_statistics.set_all(
12079 CONFIGURED_BY_STARTUP_OPTIONS_FOR_CHANNEL);
12080 }
12081 41 break;
12082 }
12083 41 case (int)OPT_REPLICATE_WILD_DO_TABLE: {
12084
3/4
✓ Branch 0 taken 41 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 29 times.
✓ Branch 3 taken 12 times.
41 if (is_rpl_global_filter_setting(argument)) {
12085
3/4
✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 28 times.
29 if (rpl_global_filter.add_wild_do_table(argument)) {
12086
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(ERROR_LEVEL, ER_RPL_FILTER_ADD_WILD_DO_TABLE_FAILED, argument);
12087 1 return true;
12088 }
12089
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 rpl_global_filter.wild_do_table_statistics.set_all(
12090 CONFIGURED_BY_STARTUP_OPTIONS);
12091 } else {
12092
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 parse_filter_arg(&channel_name, &filter_val, argument);
12093 #ifdef WITH_WSREP
12094
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
12 if (wsrep_is_wsrep_channel_name(channel_name)) {
12095 sql_print_error(
12096 "Configuration of the '%s' channel by replicate-wild-do-table is "
12097 "not allowed.",
12098 WSREP_CHANNEL_NAME);
12099 return 1;
12100 }
12101 #endif /* WITH_WSREP */
12102
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 rpl_filter = rpl_channel_filters.get_channel_filter(channel_name);
12103
3/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 11 times.
12 if (rpl_filter->add_wild_do_table(filter_val)) {
12104
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(ERROR_LEVEL, ER_RPL_FILTER_ADD_WILD_DO_TABLE_FAILED, argument);
12105 1 return true;
12106 }
12107
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 rpl_filter->wild_do_table_statistics.set_all(
12108 CONFIGURED_BY_STARTUP_OPTIONS_FOR_CHANNEL);
12109 }
12110 39 break;
12111 }
12112 43 case (int)OPT_REPLICATE_WILD_IGNORE_TABLE: {
12113
3/4
✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 31 times.
✓ Branch 3 taken 12 times.
43 if (is_rpl_global_filter_setting(argument)) {
12114
3/4
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 30 times.
31 if (rpl_global_filter.add_wild_ignore_table(argument)) {
12115
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(ERROR_LEVEL, ER_RPL_FILTER_ADD_WILD_IGNORE_TABLE_FAILED,
12116 argument);
12117 1 return true;
12118 }
12119
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 rpl_global_filter.wild_ignore_table_statistics.set_all(
12120 CONFIGURED_BY_STARTUP_OPTIONS);
12121 } else {
12122
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 parse_filter_arg(&channel_name, &filter_val, argument);
12123 #ifdef WITH_WSREP
12124
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
12 if (wsrep_is_wsrep_channel_name(channel_name)) {
12125 WSREP_ERROR(
12126 "Configuration of the '%s' channel by "
12127 "replicate-wild-ignore-table is not allowed.",
12128 WSREP_CHANNEL_NAME);
12129 return 1;
12130 }
12131 #endif /* WITH_WSREP */
12132
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 rpl_filter = rpl_channel_filters.get_channel_filter(channel_name);
12133
3/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 11 times.
12 if (rpl_filter->add_wild_ignore_table(filter_val)) {
12134
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(ERROR_LEVEL, ER_RPL_FILTER_ADD_WILD_IGNORE_TABLE_FAILED,
12135 argument);
12136 1 return true;
12137 }
12138
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 rpl_filter->wild_ignore_table_statistics.set_all(
12139 CONFIGURED_BY_STARTUP_OPTIONS_FOR_CHANNEL);
12140 }
12141 41 break;
12142 }
12143 71 case (int)OPT_REPLICATE_IGNORE_TABLE: {
12144
3/4
✓ Branch 0 taken 71 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✓ Branch 3 taken 14 times.
71 if (is_rpl_global_filter_setting(argument)) {
12145
3/4
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 56 times.
57 if (rpl_global_filter.add_ignore_table_array(argument)) {
12146
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(ERROR_LEVEL, ER_RPL_CANT_ADD_IGNORE_TABLE, argument);
12147 1 return true;
12148 }
12149
1/2
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
56 rpl_global_filter.ignore_table_statistics.set_all(
12150 CONFIGURED_BY_STARTUP_OPTIONS);
12151 } else {
12152
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 parse_filter_arg(&channel_name, &filter_val, argument);
12153 #ifdef WITH_WSREP
12154
2/4
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 14 times.
14 if (wsrep_is_wsrep_channel_name(channel_name)) {
12155 WSREP_ERROR(
12156 "Configuration of the '%s' channel by replicate-ignore-table is "
12157 "not allowed.",
12158 WSREP_CHANNEL_NAME);
12159 return 1;
12160 }
12161 #endif /* WITH_WSREP */
12162
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 rpl_filter = rpl_channel_filters.get_channel_filter(channel_name);
12163
3/4
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 13 times.
14 if (rpl_filter->add_ignore_table_array(filter_val)) {
12164
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(ERROR_LEVEL, ER_RPL_CANT_ADD_IGNORE_TABLE, argument);
12165 1 return true;
12166 }
12167
1/2
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
13 rpl_filter->ignore_table_statistics.set_all(
12168 CONFIGURED_BY_STARTUP_OPTIONS_FOR_CHANNEL);
12169 }
12170 69 break;
12171 }
12172 3037 case (int)OPT_MASTER_RETRY_COUNT:
12173
1/2
✓ Branch 0 taken 3037 times.
✗ Branch 1 not taken.
3037 push_deprecated_warn(nullptr, "--master-retry-count",
12174 "'CHANGE REPLICATION SOURCE TO "
12175 "SOURCE_RETRY_COUNT = <num>'");
12176 3037 break;
12177 case (int)OPT_SKIP_NEW:
12178 opt_specialflag |= SPECIAL_NO_NEW_FUNC;
12179 delay_key_write_options = DELAY_KEY_WRITE_NONE;
12180 myisam_concurrent_insert = 0;
12181 myisam_recover_options = HA_RECOVER_OFF;
12182 sp_automatic_privileges = false;
12183 my_enable_symlinks = false;
12184 ha_open_options &= ~(HA_OPEN_ABORT_IF_CRASHED | HA_OPEN_DELAY_KEY_WRITE);
12185 break;
12186 1 case (int)OPT_SKIP_HOST_CACHE_DEPRECATED:
12187 1 opt_specialflag |= SPECIAL_NO_HOST_CACHE;
12188
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 push_deprecated_warn(nullptr, "--skip-host-cache",
12189 "SET GLOBAL host_cache_size=0");
12190 1 break;
12191 41 case (int)OPT_SKIP_RESOLVE:
12192
5/6
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 38 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 39 times.
44 if (argument && (argument == disabled_my_option ||
12193
3/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 1 times.
3 !my_strcasecmp(system_charset_info, argument, "OFF")))
12194 2 opt_skip_name_resolve = false;
12195 else {
12196 39 opt_skip_name_resolve = true;
12197 39 opt_specialflag |= SPECIAL_NO_RESOLVE;
12198 }
12199 41 break;
12200 8995 case (int)OPT_WANT_CORE:
12201 8995 test_flags |= TEST_CORE_ON_SIGNAL;
12202 8995 opt_corefile = (argument != disabled_my_option);
12203 8995 break;
12204 10 case (int)OPT_COREDUMPER:
12205 10 test_flags |= TEST_CORE_ON_SIGNAL;
12206 10 opt_libcoredumper = (argument != disabled_my_option);
12207 10 break;
12208 18 case (int)OPT_SKIP_STACK_TRACE:
12209 18 test_flags |= TEST_NO_STACKTRACE;
12210 18 break;
12211 9905 case OPT_SERVER_ID:
12212 /*
12213 Consider that one received a Server Id when 2 conditions are present:
12214 1) The argument is on the list
12215 2) There is a value present
12216 */
12217 9905 server_id_supplied = (*argument != 0);
12218 9905 break;
12219 175 case OPT_LOWER_CASE_TABLE_NAMES:
12220 175 lower_case_table_names_used = true;
12221 175 break;
12222 #if defined(ENABLED_DEBUG_SYNC)
12223 8913 case OPT_DEBUG_SYNC_TIMEOUT:
12224 /*
12225 Debug Sync Facility. See debug_sync.cc.
12226 Default timeout for WAIT_FOR action.
12227 Default value is zero (facility disabled).
12228 If option is given without an argument, supply a non-zero value.
12229 */
12230
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8913 times.
8913 if (!argument) {
12231 /* purecov: begin tested */
12232 opt_debug_sync_timeout = DEBUG_SYNC_DEFAULT_WAIT_TIMEOUT;
12233 /* purecov: end */
12234 }
12235 8913 break;
12236 #endif /* defined(ENABLED_DEBUG_SYNC) */
12237 1137 case OPT_LOG_ERROR:
12238 /*
12239 "No --log-error" == "write errors to stderr",
12240 "--log-error without argument" == "write errors to a file".
12241 */
12242
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1135 times.
1137 if (argument == nullptr) /* no argument */
12243 2 log_error_dest = "";
12244 1137 break;
12245
12246 513 case OPT_EARLY_PLUGIN_LOAD:
12247
1/2
✓ Branch 0 taken 513 times.
✗ Branch 1 not taken.
513 free_list(opt_early_plugin_load_list_ptr);
12248
2/4
✓ Branch 0 taken 513 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 513 times.
✗ Branch 3 not taken.
513 opt_early_plugin_load_list_ptr->push_back(new i_string(argument));
12249 513 break;
12250 1684 case OPT_PLUGIN_LOAD:
12251
1/2
✓ Branch 0 taken 1684 times.
✗ Branch 1 not taken.
1684 free_list(opt_plugin_load_list_ptr);
12252 [[fallthrough]];
12253 1690 case OPT_PLUGIN_LOAD_ADD:
12254
2/4
✓ Branch 0 taken 1690 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1690 times.
✗ Branch 3 not taken.
1690 opt_plugin_load_list_ptr->push_back(new i_string(argument));
12255 1690 break;
12256 9468 case OPT_PFS_INSTRUMENT: {
12257 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
12258 /*
12259 Parse instrument name and value from argument string. Handle leading
12260 and trailing spaces. Also handle single quotes.
12261
12262 Acceptable:
12263 performance_schema_instrument = ' foo/%/bar/ = ON '
12264 performance_schema_instrument = '%=OFF'
12265 Not acceptable:
12266 performance_schema_instrument = '' foo/%/bar = ON ''
12267 performance_schema_instrument = '%='OFF''
12268 */
12269 9468 char *name = argument, *p = nullptr, *val = nullptr;
12270 9468 bool quote = false; /* true if quote detected */
12271 9468 bool error = true; /* false if no errors detected */
12272 9468 const int PFS_BUFFER_SIZE = 128;
12273 char orig_argument[PFS_BUFFER_SIZE + 1];
12274 9468 orig_argument[0] = 0;
12275
12276
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9468 times.
9468 if (!argument) goto pfs_error;
12277
12278 /* Save original argument string for error reporting */
12279 9468 strncpy(orig_argument, argument, PFS_BUFFER_SIZE);
12280
12281 /* Split instrument name and value at the equal sign */
12282
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 9464 times.
9468 if (!(p = strchr(argument, '='))) goto pfs_error;
12283
12284 /* Get option value */
12285 9464 val = p + 1;
12286
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9464 times.
9464 if (!*val) goto pfs_error;
12287
12288 /* Trim leading spaces and quote from the instrument name */
12289
5/6
✓ Branch 0 taken 9476 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 9468 times.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 9464 times.
9476 while (*name && (my_isspace(mysqld_charset, *name) || (*name == '\''))) {
12290 /* One quote allowed */
12291
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 8 times.
12 if (*name == '\'') {
12292
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (!quote)
12293 4 quote = true;
12294 else
12295 goto pfs_error;
12296 }
12297 12 name++;
12298 }
12299
12300 /* Trim trailing spaces from instrument name */
12301
3/4
✓ Branch 0 taken 9485 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
✓ Branch 3 taken 9464 times.
9485 while ((p > name) && my_isspace(mysqld_charset, p[-1])) p--;
12302 9464 *p = 0;
12303
12304 /* Remove trailing slash from instrument name */
12305
3/4
✓ Branch 0 taken 9464 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 9463 times.
9464 if (p > name && (p[-1] == '/')) p[-1] = 0;
12306
12307
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9464 times.
9464 if (!*name) goto pfs_error;
12308
12309 /* Trim leading spaces from option value */
12310
3/4
✓ Branch 0 taken 9480 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 9464 times.
9480 while (*val && my_isspace(mysqld_charset, *val)) val++;
12311
12312 /* Trim trailing spaces and matching quote from value */
12313 9464 p = val + strlen(val);
12314
5/6
✓ Branch 0 taken 9473 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 9468 times.
✓ Branch 4 taken 5 times.
✓ Branch 5 taken 9463 times.
9473 while (p > val && (my_isspace(mysqld_charset, p[-1]) || p[-1] == '\'')) {
12315 /* One matching quote allowed */
12316
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
10 if (p[-1] == '\'') {
12317
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 if (quote)
12318 4 quote = false;
12319 else
12320 1 goto pfs_error;
12321 }
12322 9 p--;
12323 }
12324
12325 9463 *p = 0;
12326
12327
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9463 times.
9463 if (!*val) goto pfs_error;
12328
12329 /* Add instrument name and value to array of configuration options */
12330
3/4
✓ Branch 0 taken 9463 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 9461 times.
9463 if (add_pfs_instr_to_array(name, val)) goto pfs_error;
12331
12332 9461 error = false;
12333
12334 9468 pfs_error:
12335
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 9461 times.
9468 if (error) {
12336
8/16
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 7 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 7 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 7 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 7 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 7 times.
✗ Branch 15 not taken.
7 LogErr(WARNING_LEVEL, ER_INVALID_INSTRUMENT, orig_argument);
12337 7 return false;
12338 }
12339 #endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
12340 9461 break;
12341 }
12342 2 case OPT_THREAD_CACHE_SIZE:
12343 2 thread_cache_size_specified = true;
12344 2 break;
12345 2 case OPT_HOST_CACHE_SIZE:
12346 2 host_cache_size_specified = true;
12347 2 break;
12348 2 case OPT_TABLE_DEFINITION_CACHE:
12349 2 table_definition_cache_specified = true;
12350 2 break;
12351 7 case OPT_SKIP_INNODB:
12352
8/16
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 7 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 7 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 7 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 7 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 7 times.
✗ Branch 15 not taken.
7 LogErr(WARNING_LEVEL, ER_INNODB_MANDATORY);
12353 7 break;
12354 case OPT_AVOID_TEMPORAL_UPGRADE:
12355 push_deprecated_warn_no_replacement(nullptr, "avoid_temporal_upgrade");
12356 break;
12357 case OPT_SHOW_OLD_TEMPORALS:
12358 push_deprecated_warn_no_replacement(nullptr, "show_old_temporals");
12359 break;
12360 case 'p':
12361 if (argument) {
12362 char *start = argument;
12363 my_free(opt_keyring_migration_password);
12364 opt_keyring_migration_password =
12365 my_strdup(PSI_NOT_INSTRUMENTED, argument, MYF(MY_FAE));
12366 while (*argument) *argument++ = 'x';
12367 if (*start) start[1] = 0;
12368 } else
12369 opt_keyring_migration_password = get_tty_password(NullS);
12370 migrate_connect_options = true;
12371 break;
12372 case OPT_KEYRING_MIGRATION_USER:
12373 case OPT_KEYRING_MIGRATION_HOST:
12374 case OPT_KEYRING_MIGRATION_SOCKET:
12375 case OPT_KEYRING_MIGRATION_PORT:
12376 migrate_connect_options = true;
12377 break;
12378 482 case OPT_LOG_REPLICA_UPDATES:
12379 482 log_replica_updates_supplied = true;
12380 482 break;
12381 139 case OPT_REPLICA_PRESERVE_COMMIT_ORDER:
12382 139 replica_preserve_commit_order_supplied = true;
12383 139 break;
12384 2782 case OPT_ENFORCE_GTID_CONSISTENCY: {
12385 const char *wrong_value =
12386
1/2
✓ Branch 0 taken 2782 times.
✗ Branch 1 not taken.
2782 fixup_enforce_gtid_consistency_command_line(argument);
12387
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2778 times.
2782 if (wrong_value != nullptr)
12388
8/16
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 4 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 4 times.
✗ Branch 15 not taken.
4 LogErr(WARNING_LEVEL, ER_INVALID_VALUE_FOR_ENFORCE_GTID_CONSISTENCY,
12389 wrong_value);
12390 2782 } break;
12391 case OPT_NAMED_PIPE_FULL_ACCESS_GROUP:
12392 #ifdef _WIN32
12393 if (!is_valid_named_pipe_full_access_group(argument)) {
12394 LogErr(ERROR_LEVEL, ER_INVALID_NAMED_PIPE_FULL_ACCESS_GROUP);
12395 return 1;
12396 }
12397 #endif // _WIN32
12398 break;
12399 4 case OPT_RELAY_LOG_INFO_FILE:
12400
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 push_deprecated_warn_no_replacement(nullptr, "--relay-log-info-file");
12401 4 break;
12402 5 case OPT_MASTER_INFO_FILE:
12403
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 push_deprecated_warn_no_replacement(nullptr, "--master-info-file");
12404 5 break;
12405 4 case OPT_LOG_BIN_USE_V1_ROW_EVENTS:
12406
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 push_deprecated_warn_no_replacement(nullptr,
12407 "--log-bin-use-v1-row-events");
12408 4 break;
12409 1 case OPT_SLAVE_ROWS_SEARCH_ALGORITHMS:
12410
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 push_deprecated_warn_no_replacement(nullptr,
12411 "--slave-rows-search-algorithms");
12412 1 break;
12413 #ifdef WITH_WSREP
12414 108 case OPT_WSREP_START_POSITION: {
12415
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 wsrep_start_position_init(argument);
12416 108 break;
12417 }
12418 #endif /* WITH_WSREP */
12419 74 case OPT_MASTER_INFO_REPOSITORY:
12420
1/2
✓ Branch 0 taken 74 times.
✗ Branch 1 not taken.
74 push_deprecated_warn_no_replacement(nullptr, "--master-info-repository");
12421 74 break;
12422 276 case OPT_RELAY_LOG_INFO_REPOSITORY:
12423
1/2
✓ Branch 0 taken 276 times.
✗ Branch 1 not taken.
276 push_deprecated_warn_no_replacement(nullptr,
12424 "--relay-log-info-repository");
12425 276 break;
12426 95 case OPT_TRANSACTION_WRITE_SET_EXTRACTION:
12427
1/2
✓ Branch 0 taken 95 times.
✗ Branch 1 not taken.
95 push_deprecated_warn_no_replacement(nullptr,
12428 "--transaction-write-set-extraction");
12429 95 break;
12430 1 case OPT_DISCONNECT_SLAVE_EVENT_COUNT:
12431
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 push_deprecated_warn_no_replacement(nullptr,
12432 "--disconnect-slave-event-count");
12433 1 break;
12434 1 case OPT_ABORT_SLAVE_EVENT_COUNT:
12435
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 push_deprecated_warn_no_replacement(nullptr, "--abort-slave-event-count");
12436 1 break;
12437 106 case OPT_REPLICA_PARALLEL_TYPE:
12438
1/2
✓ Branch 0 taken 106 times.
✗ Branch 1 not taken.
106 push_deprecated_warn_no_replacement(nullptr, "--replica-parallel-type");
12439 106 break;
12440 166 case OPT_REPLICA_PARALLEL_WORKERS:
12441
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 152 times.
166 if (opt_mts_replica_parallel_workers == 0) {
12442
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 push_deprecated_warn(nullptr, "--replica-parallel-workers=0",
12443 "'--replica-parallel-workers=1'");
12444 }
12445 166 break;
12446 1 case OPT_OLD_STYLE_USER_LIMITS:
12447
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 push_deprecated_warn_no_replacement(nullptr, "--old-style-user-limits");
12448 }
12449 629790 return false;
12450 }
12451
12452 /** Handle arguments for multiple key caches. */
12453
12454 39356 static void *mysql_getopt_value(const char *keyname, size_t key_length,
12455 const struct my_option *option, int *error) {
12456
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 39352 times.
39356 if (error) *error = 0;
12457
1/2
✓ Branch 0 taken 39356 times.
✗ Branch 1 not taken.
39356 switch (option->id) {
12458 39356 case OPT_KEY_BUFFER_SIZE:
12459 case OPT_KEY_CACHE_BLOCK_SIZE:
12460 case OPT_KEY_CACHE_DIVISION_LIMIT:
12461 case OPT_KEY_CACHE_AGE_THRESHOLD: {
12462 KEY_CACHE *key_cache;
12463 78712 if (!(key_cache =
12464
3/6
✓ Branch 0 taken 39356 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39356 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 39356 times.
39356 get_or_create_key_cache(std::string{keyname, key_length}))) {
12465 if (error) *error = EXIT_OUT_OF_MEMORY;
12466 return nullptr;
12467 }
12468
4/5
✓ Branch 0 taken 9842 times.
✓ Branch 1 taken 9838 times.
✓ Branch 2 taken 9838 times.
✓ Branch 3 taken 9838 times.
✗ Branch 4 not taken.
39356 switch (option->id) {
12469 9842 case OPT_KEY_BUFFER_SIZE:
12470 9842 return &key_cache->param_buff_size;
12471 9838 case OPT_KEY_CACHE_BLOCK_SIZE:
12472 9838 return &key_cache->param_block_size;
12473 9838 case OPT_KEY_CACHE_DIVISION_LIMIT:
12474 9838 return &key_cache->param_division_limit;
12475 9838 case OPT_KEY_CACHE_AGE_THRESHOLD:
12476 9838 return &key_cache->param_age_threshold;
12477 }
12478 }
12479 }
12480 return option->value;
12481 }
12482
12483 /**
12484 Get server options from the command line,
12485 and perform related server initializations.
12486 @param [in, out] argc_ptr command line options (count)
12487 @param [in, out] argv_ptr command line options (values)
12488 @return 0 on success
12489
12490 @todo
12491 - FIXME add EXIT_TOO_MANY_ARGUMENTS to "mysys_err.h" and return that code?
12492 */
12493 9824 static int get_options(int *argc_ptr, char ***argv_ptr) {
12494 int ho_error;
12495
12496 9824 my_getopt_register_get_addr(mysql_getopt_value);
12497
12498 /* prepare all_options array */
12499 9824 all_options.reserve(array_elements(my_long_options));
12500 687680 for (my_option *opt = my_long_options;
12501
2/2
✓ Branch 0 taken 677856 times.
✓ Branch 1 taken 9824 times.
687680 opt < my_long_options + array_elements(my_long_options) - 1; opt++) {
12502 677856 all_options.push_back(*opt);
12503 }
12504 9824 sys_var_add_options(&all_options, sys_var::PARSE_NORMAL);
12505 9824 add_terminator(&all_options);
12506
12507 /* Skip unknown options so that they may be processed later by plugins */
12508 9824 my_getopt_skip_unknown = true;
12509
12510
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 9793 times.
9824 if ((ho_error = handle_options(argc_ptr, argv_ptr, &all_options[0],
12511 mysqld_get_one_option)))
12512 31 return ho_error;
12513
12514 // update suppression list in filter engine
12515 {
12516 int rr;
12517 // try to set the list
12518 9793 if (((rr = log_builtins_filter_parse_suppression_list(
12519
4/4
✓ Branch 0 taken 9791 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 13 times.
✓ Branch 3 taken 9780 times.
19584 opt_log_error_suppression_list, false)) != 0) ||
12520
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 9780 times.
9791 ((rr = log_builtins_filter_parse_suppression_list(
12521 opt_log_error_suppression_list, true)) != 0)) {
12522 13 rr = -(rr + 1);
12523
7/14
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 13 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 13 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 13 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 13 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 13 times.
✗ Branch 13 not taken.
13 LogErr(ERROR_LEVEL, ER_CANT_SET_ERROR_SUPPRESSION_LIST_FROM_COMMAND_LINE,
12524 "log_error_suppression_list", &opt_log_error_suppression_list[rr]);
12525
12526 /*
12527 We were given an illegal value at start-up, so the default will be
12528 used instead. We have reported the problem (and the dodgy value);
12529 let's now point our variable back at the default (i.e. the value
12530 actually used) so SELECT @@GLOBAL.log_error_suppression_list will
12531 render correct results.
12532 */
12533
2/4
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
✗ Branch 3 not taken.
13 sys_var *var = find_static_system_variable("log_error_suppression_list");
12534
1/2
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
13 if (var != nullptr) {
12535 13 opt_log_error_suppression_list = (char *)var->get_default();
12536 /*
12537 During unit-testing, the log subsystem is not initialized,
12538 so while the default should always check out as a valid
12539 argument, actually setting it will still fail in this
12540 particular case as we cannot acquire the rule-set or its
12541 lock.
12542 */
12543 13 if (log_builtins_filter_parse_suppression_list(
12544
1/2
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
13 opt_log_error_suppression_list, false) == 0) {
12545 13 log_builtins_filter_parse_suppression_list(
12546 opt_log_error_suppression_list, true);
12547 } else {
12548 assert(false); /* purecov: inspected */
12549 }
12550 }
12551 }
12552 }
12553
12554
2/2
✓ Branch 0 taken 9775 times.
✓ Branch 1 taken 18 times.
9793 if (!is_help_or_validate_option())
12555 9775 vector<my_option>().swap(all_options); // Deletes the vector contents.
12556
12557 /* Add back the program name handle_options removes */
12558 9793 (*argc_ptr)++;
12559 9793 (*argv_ptr)--;
12560
12561 /*
12562 Options have been parsed. Now some of them need additional special
12563 handling, like custom value checking, checking of incompatibilites
12564 between options, setting of multiple variables, etc.
12565 Do them here.
12566 */
12567
12568
11/18
✓ Branch 0 taken 9780 times.
✓ Branch 1 taken 13 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 9779 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
9793 if (!opt_help && opt_verbose) LogErr(ERROR_LEVEL, ER_VERBOSE_REQUIRES_HELP);
12569
12570
4/4
✓ Branch 0 taken 9783 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 9778 times.
✓ Branch 3 taken 5 times.
9791 if ((opt_log_slow_admin_statements || opt_log_queries_not_using_indexes ||
12571
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9778 times.
9778 opt_log_slow_replica_statements ||
12572
3/4
✓ Branch 0 taken 9791 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9793 times.
29364 global_system_variables.log_query_errors.check_variable_set()) &&
12573
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 !opt_slow_log)
12574 LogErr(WARNING_LEVEL, ER_POINTLESS_WITHOUT_SLOWLOG);
12575
12576 9793 if (global_system_variables.net_buffer_length >
12577
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9793 times.
9793 global_system_variables.max_allowed_packet) {
12578 LogErr(WARNING_LEVEL, ER_WASTEFUL_NET_BUFFER_SIZE,
12579 global_system_variables.net_buffer_length,
12580 global_system_variables.max_allowed_packet);
12581 }
12582
12583 /*
12584 TIMESTAMP columns get implicit DEFAULT values when
12585 --explicit_defaults_for_timestamp is not set.
12586 This behavior is deprecated now.
12587 */
12588
4/4
✓ Branch 0 taken 9775 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 9790 times.
19568 if (!is_help_or_validate_option() &&
12589
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 9772 times.
9775 !global_system_variables.explicit_defaults_for_timestamp)
12590
7/14
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
3 LogErr(WARNING_LEVEL, ER_DEPRECATED_TIMESTAMP_IMPLICIT_DEFAULTS);
12591
12592 9793 opt_init_connect.length = strlen(opt_init_connect.str);
12593 9793 opt_init_replica.length = strlen(opt_init_replica.str);
12594 9793 opt_mandatory_roles.length = strlen(opt_mandatory_roles.str);
12595
12596
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9793 times.
9793 if (global_system_variables.low_priority_updates)
12597 thr_upgraded_concurrent_insert_lock = TL_WRITE_LOW_PRIORITY;
12598
12599
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9793 times.
9793 if (ft_boolean_check_syntax_string(
12600 pointer_cast<const uchar *>(ft_boolean_syntax))) {
12601 LogErr(ERROR_LEVEL, ER_FT_BOOL_SYNTAX_INVALID, ft_boolean_syntax);
12602 return 1;
12603 }
12604
12605
6/6
✓ Branch 0 taken 229 times.
✓ Branch 1 taken 9564 times.
✓ Branch 2 taken 226 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 226 times.
✓ Branch 5 taken 9567 times.
9793 if (opt_noacl && !is_help_or_validate_option()) opt_disable_networking = true;
12606
12607
2/2
✓ Branch 0 taken 571 times.
✓ Branch 1 taken 9222 times.
9793 if (opt_disable_networking) mysqld_port = 0;
12608
12609
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9793 times.
9793 if (opt_skip_show_db) opt_specialflag |= SPECIAL_SKIP_SHOW_DB;
12610
12611
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9793 times.
9793 if (myisam_flush) flush_time = 0;
12612
12613
2/2
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 9759 times.
9793 if (opt_replica_skip_errors) add_replica_skip_errors(opt_replica_skip_errors);
12614
12615
1/2
✓ Branch 0 taken 9793 times.
✗ Branch 1 not taken.
9793 if (global_system_variables.max_join_size == HA_POS_ERROR)
12616 9793 global_system_variables.option_bits |= OPTION_BIG_SELECTS;
12617 else
12618 global_system_variables.option_bits &= ~OPTION_BIG_SELECTS;
12619
12620 #ifdef WITH_WSREP
12621
2/2
✓ Branch 0 taken 741 times.
✓ Branch 1 taken 9052 times.
9793 if (global_system_variables.wsrep_causal_reads) {
12622
9/18
✓ Branch 0 taken 741 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 741 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 741 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 741 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 741 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 741 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 741 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 741 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 17 taken 741 times.
741 WSREP_WARN(
12623 "Option --wsrep-causal-reads is deprecated."
12624 " Please start using --wsrep-sync-wait.");
12625
12626
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 741 times.
741 if (!(global_system_variables.wsrep_sync_wait &
12627 WSREP_SYNC_WAIT_BEFORE_READ)) {
12628 WSREP_WARN(
12629 "--wsrep-causal-reads=ON takes precedence over --wsrep-sync-wait=%u. "
12630 "WSREP_SYNC_WAIT_BEFORE_READ is on",
12631 global_system_variables.wsrep_sync_wait);
12632 global_system_variables.wsrep_sync_wait |= WSREP_SYNC_WAIT_BEFORE_READ;
12633 } else {
12634 // they are turned on both.
12635 }
12636 } else {
12637
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9052 times.
9052 if (global_system_variables.wsrep_sync_wait & WSREP_SYNC_WAIT_BEFORE_READ) {
12638 WSREP_WARN(
12639 "--wsrep-sync-wait=%u takes precedence over "
12640 "--wsrep-causal-reads=OFF. "
12641 "WSREP_SYNC_WAIT_BEFORE_READ is on",
12642 global_system_variables.wsrep_sync_wait);
12643 global_system_variables.wsrep_causal_reads = 1;
12644 } else {
12645 // they are turned off both.
12646 }
12647 }
12648 #endif /* WITH_WSREP */
12649
12650 // Synchronize @@global.autocommit value on --autocommit
12651 9793 const ulonglong turn_bit_on =
12652
2/2
✓ Branch 0 taken 9788 times.
✓ Branch 1 taken 5 times.
9793 opt_autocommit ? OPTION_AUTOCOMMIT : OPTION_NOT_AUTOCOMMIT;
12653 9793 global_system_variables.option_bits =
12654 9793 (global_system_variables.option_bits &
12655 9793 ~(OPTION_NOT_AUTOCOMMIT | OPTION_AUTOCOMMIT)) |
12656 turn_bit_on;
12657
12658 // Synchronize @@global.autocommit metadata on --autocommit
12659 9793 my_option *opt = &my_long_options[3];
12660
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9793 times.
9793 assert(strcmp(opt->name, "autocommit") == 0);
12661
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9793 times.
9793 assert(opt->arg_source != nullptr);
12662 9793 Sys_autocommit_ptr->set_source_name(opt->arg_source->m_path_name);
12663 9793 Sys_autocommit_ptr->set_source(opt->arg_source->m_source);
12664
12665 9793 global_system_variables.sql_mode =
12666 9793 expand_sql_mode(global_system_variables.sql_mode, nullptr);
12667
12668
2/2
✓ Branch 0 taken 9791 times.
✓ Branch 1 taken 2 times.
9793 if (!my_enable_symlinks) have_symlink = SHOW_OPTION_DISABLED;
12669
12670 /* Set global MyISAM variables from delay_key_write_options */
12671 9793 fix_delay_key_write(nullptr, nullptr, OPT_GLOBAL);
12672
12673 #ifndef _WIN32
12674
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9793 times.
9793 if (mysqld_chroot) set_root(mysqld_chroot);
12675 #endif
12676
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 9790 times.
9793 if (fix_paths()) return 1;
12677
12678 /*
12679 Set some global variables from the global_system_variables
12680 In most cases the global variables will not be used
12681 */
12682 9790 my_disable_locking = myisam_single_user = (opt_external_locking == 0);
12683 9790 my_default_record_cache_size = global_system_variables.read_buff_size;
12684
12685 9790 global_system_variables.long_query_time =
12686 9790 (ulonglong)(global_system_variables.long_query_time_double * 1e6);
12687
12688 9790 init_log_slow_verbosity();
12689 9790 init_slow_query_log_use_global_control();
12690 9790 init_log_slow_sp_statements();
12691
12692
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9790 times.
9790 if (opt_short_log_format) opt_specialflag |= SPECIAL_SHORT_LOG_FORMAT;
12693
12694
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9790 times.
9790 if (Connection_handler_manager::init()) {
12695 LogErr(ERROR_LEVEL, ER_CONNECTION_HANDLING_OOM);
12696 return 1;
12697 }
12698
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9790 times.
9790 if (Global_THD_manager::create_instance()) {
12699 LogErr(ERROR_LEVEL, ER_THREAD_HANDLING_OOM);
12700 return 1;
12701 }
12702
12703 /* If --super-read-only was specified, set read_only to 1 */
12704
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 9779 times.
9790 read_only = super_read_only ? super_read_only : read_only;
12705 9790 opt_readonly = read_only;
12706
12707 9790 return 0;
12708 9790 }
12709
12710 /*
12711 Create version name for running mysqld version
12712 We automatically add suffixes -debug, -valgrind, -asan, -ubsan
12713 to the version name to make the version more descriptive.
12714 (MYSQL_SERVER_SUFFIX is set by the compilation environment)
12715 */
12716
12717 /*
12718 The following code is quite ugly as there is no portable way to easily set a
12719 string to the value of a macro
12720 */
12721 #ifdef MYSQL_SERVER_SUFFIX
12722 #define MYSQL_SERVER_SUFFIX_STR STRINGIFY_ARG(MYSQL_SERVER_SUFFIX)
12723 #else
12724 #define MYSQL_SERVER_SUFFIX_STR MYSQL_SERVER_SUFFIX_DEF
12725 #endif
12726
12727 10111 static void set_server_version(void) {
12728 10111 char *end [[maybe_unused]] = strxmov(server_version, MYSQL_SERVER_VERSION,
12729 MYSQL_SERVER_SUFFIX_STR, NullS);
12730 #ifndef NDEBUG
12731
1/2
✓ Branch 0 taken 10111 times.
✗ Branch 1 not taken.
10111 if (!strstr(MYSQL_SERVER_SUFFIX_STR, "-debug"))
12732 10111 end = my_stpcpy(end, "-debug");
12733 #endif
12734 #ifdef HAVE_VALGRIND
12735 if (SERVER_VERSION_LENGTH - (end - server_version) >
12736 static_cast<int>(sizeof("-valgrind")))
12737 end = my_stpcpy(end, "-valgrind");
12738 #endif
12739 #ifdef HAVE_ASAN
12740 if (SERVER_VERSION_LENGTH - (end - server_version) >
12741 static_cast<int>(sizeof("-asan")))
12742 end = my_stpcpy(end, "-asan");
12743 #endif
12744 #ifdef HAVE_LSAN
12745 if (SERVER_VERSION_LENGTH - (end - server_version) >
12746 static_cast<int>(sizeof("-lsan")))
12747 end = my_stpcpy(end, "-lsan");
12748 #endif
12749 #ifdef HAVE_UBSAN
12750 if (SERVER_VERSION_LENGTH - (end - server_version) >
12751 static_cast<int>(sizeof("-ubsan")))
12752 end = my_stpcpy(end, "-ubsan");
12753 #endif
12754 #ifdef HAVE_TSAN
12755 if (SERVER_VERSION_LENGTH - (end - server_version) >
12756 static_cast<int>(sizeof("-tsan")))
12757 end = my_stpcpy(end, "-tsan");
12758 #endif
12759
12760
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10111 times.
10111 assert(end < server_version + SERVER_VERSION_LENGTH);
12761 10111 my_stpcpy(server_version_suffix,
12762 server_version + strlen(MYSQL_SERVER_VERSION));
12763 10111 }
12764
12765 32306 static const char *get_relative_path(const char *path) {
12766
5/6
✓ Branch 0 taken 32306 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22170 times.
✓ Branch 3 taken 10136 times.
✓ Branch 4 taken 22170 times.
✓ Branch 5 taken 10136 times.
32306 if (test_if_hard_path(path) && is_prefix(path, DEFAULT_MYSQL_HOME) &&
12767 strcmp(DEFAULT_MYSQL_HOME, FN_ROOTDIR)) {
12768 22170 path += strlen(DEFAULT_MYSQL_HOME);
12769
2/2
✓ Branch 0 taken 22170 times.
✓ Branch 1 taken 22170 times.
44340 while (is_directory_separator(*path)) path++;
12770 }
12771 32306 return path;
12772 }
12773
12774 59756 static bool is_secure_path(const char *path, const char *opt_base) {
12775 char buff1[FN_REFLEN], buff2[FN_REFLEN];
12776 size_t opt_base_len;
12777 /*
12778 All paths are secure if opt_base is 0
12779 */
12780
2/2
✓ Branch 0 taken 213 times.
✓ Branch 1 taken 59543 times.
59756 if (!opt_base[0]) return true;
12781
12782 59543 opt_base_len = strlen(opt_base);
12783
12784
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59543 times.
59543 if (strlen(path) >= FN_REFLEN) return false;
12785
12786
3/4
✓ Branch 0 taken 59543 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 59536 times.
59543 if (!my_strcasecmp(system_charset_info, opt_base, "NULL")) return false;
12787
12788
3/4
✓ Branch 0 taken 59536 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15054 times.
✓ Branch 3 taken 44482 times.
59536 if (my_realpath(buff1, path, 0)) {
12789 /*
12790 The supplied file path might have been a file and not a directory.
12791 */
12792
1/2
✓ Branch 0 taken 15054 times.
✗ Branch 1 not taken.
15054 int length = (int)dirname_length(path);
12793
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15054 times.
15054 if (length >= FN_REFLEN) return false;
12794 15054 memcpy(buff2, path, length);
12795 15054 buff2[length] = '\0';
12796
6/8
✓ Branch 0 taken 15054 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15054 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
✓ Branch 5 taken 15036 times.
✓ Branch 6 taken 18 times.
✓ Branch 7 taken 15036 times.
15054 if (length == 0 || my_realpath(buff1, buff2, 0)) return false;
12797 }
12798
1/2
✓ Branch 0 taken 59518 times.
✗ Branch 1 not taken.
59518 convert_dirname(buff2, buff1, NullS);
12799
1/2
✓ Branch 0 taken 59518 times.
✗ Branch 1 not taken.
59518 if (!lower_case_file_system) {
12800
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 59487 times.
59518 if (strncmp(opt_base, buff2, opt_base_len)) return false;
12801 } else {
12802 if (files_charset_info->coll->strnncoll(
12803 files_charset_info, (uchar *)buff2, strlen(buff2),
12804 pointer_cast<const uchar *>(opt_base), opt_base_len, true))
12805 return false;
12806 }
12807 59487 return true;
12808 }
12809
12810 /**
12811 Test a file path to determine if the path is compatible with the secure file
12812 path restriction.
12813
12814 @param path null terminated character string
12815
12816 @retval true The path is secure
12817 @retval false The path isn't secure
12818 */
12819 59650 bool is_secure_file_path(const char *path) {
12820 59650 return is_secure_path(path, opt_secure_file_priv);
12821 }
12822
12823 /**
12824 Test a file path to determine if the path is compatible with the secure log
12825 path restriction.
12826
12827 @param path null terminated character string
12828
12829 @retval true The path is secure
12830 @retval false The path isn't secure
12831 */
12832 106 bool is_secure_log_path(const char *path) {
12833 106 return is_secure_path(path, opt_secure_log_path);
12834 }
12835
12836 /**
12837 check_secure_file_priv_path : Checks path specified through
12838 --secure-file-priv and raises warning in following cases:
12839 1. If path is empty string or NULL and mysqld is not running
12840 with --initialize (bootstrap mode).
12841 2. If path can access data directory
12842 3. If path points to a directory which is accessible by
12843 all OS users (non-Windows build only)
12844
12845 It throws error in following cases:
12846
12847 1. If path normalization fails
12848 2. If it can not get stats of the directory
12849
12850 Assumptions :
12851 1. Data directory path has been normalized
12852 2. opt_secure_file_priv has been normalized unless it is set
12853 to "NULL".
12854
12855 @returns Status of validation
12856 @retval true : Validation is successful with/without warnings
12857 @retval false : Validation failed. Error is raised.
12858 */
12859
12860 19554 static bool check_secure_path(const char *opt_var, const char *variable_name,
12861 int warn_empty_err) {
12862 19554 char datadir_buffer[FN_REFLEN + 1] = {0};
12863 19554 char plugindir_buffer[FN_REFLEN + 1] = {0};
12864 19554 char whichdir[20] = {0};
12865 19554 size_t opt_plugindir_len = 0;
12866 19554 size_t opt_datadir_len = 0;
12867 19554 size_t opt_var_len = 0;
12868 19554 bool warn = false;
12869 bool case_insensitive_fs;
12870 #ifndef _WIN32
12871 MY_STAT dir_stat;
12872 #endif
12873
12874
2/2
✓ Branch 0 taken 10229 times.
✓ Branch 1 taken 9325 times.
19554 if (!opt_var[0]) {
12875
2/2
✓ Branch 0 taken 424 times.
✓ Branch 1 taken 9805 times.
10229 if (opt_initialize) {
12876 /*
12877 Do not impose --secure-file-priv restriction
12878 in bootstrap mode
12879 */
12880
8/16
✓ Branch 0 taken 424 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 424 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 424 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 424 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 424 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 424 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 424 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 424 times.
✗ Branch 15 not taken.
424 LogErr(INFORMATION_LEVEL, ER_SEC_FILE_PRIV_IGNORED, variable_name);
12881 } else {
12882
8/16
✓ Branch 0 taken 9805 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9805 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9805 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 9805 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 9805 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 9805 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 9805 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 9805 times.
✗ Branch 15 not taken.
9805 LogErr(WARNING_LEVEL, ER_SEC_FILE_PRIV_EMPTY, variable_name);
12883 }
12884 10229 return true;
12885 }
12886
12887 /*
12888 Setting --secure-file-priv to NULL would disable
12889 reading/writing from/to file
12890 */
12891
3/4
✓ Branch 0 taken 9325 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 27 times.
✓ Branch 3 taken 9298 times.
9325 if (!my_strcasecmp(system_charset_info, opt_var, "NULL")) {
12892
8/16
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 27 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 27 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 27 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 27 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 27 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 27 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 27 times.
✗ Branch 15 not taken.
27 LogErr(INFORMATION_LEVEL, warn_empty_err, variable_name);
12893 27 return true;
12894 }
12895
12896 /*
12897 Check if --secure-file-priv can access data directory
12898 */
12899 9298 opt_var_len = strlen(opt_var);
12900
12901 /*
12902 Adds dir separator at the end.
12903 This is required in subsequent comparison
12904 */
12905
1/2
✓ Branch 0 taken 9298 times.
✗ Branch 1 not taken.
9298 convert_dirname(datadir_buffer, mysql_unpacked_real_data_home, NullS);
12906 9298 opt_datadir_len = strlen(datadir_buffer);
12907
12908
1/2
✓ Branch 0 taken 9298 times.
✗ Branch 1 not taken.
9298 case_insensitive_fs = (test_if_case_insensitive(datadir_buffer) == 1);
12909
12910
1/2
✓ Branch 0 taken 9298 times.
✗ Branch 1 not taken.
9298 if (!case_insensitive_fs) {
12911
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9298 times.
✓ Branch 2 taken 8856 times.
✓ Branch 3 taken 442 times.
9298 if (!strncmp(
12912 datadir_buffer, opt_var,
12913 opt_datadir_len < opt_var_len ? opt_datadir_len : opt_var_len)) {
12914 8856 warn = true;
12915 8856 strcpy(whichdir, "Data directory");
12916 }
12917 } else {
12918 if (!files_charset_info->coll->strnncoll(
12919 files_charset_info, (uchar *)datadir_buffer, opt_datadir_len,
12920 pointer_cast<const uchar *>(opt_var), opt_var_len, true)) {
12921 warn = true;
12922 strcpy(whichdir, "Data directory");
12923 }
12924 }
12925
12926 /*
12927 Don't bother comparing --secure-file-priv with --plugin-dir
12928 if we already have a match against --datdir or
12929 --plugin-dir is not pointing to a valid directory.
12930 */
12931
6/8
✓ Branch 0 taken 442 times.
✓ Branch 1 taken 8856 times.
✓ Branch 2 taken 442 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 442 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 442 times.
✓ Branch 7 taken 8856 times.
9298 if (!warn && !my_realpath(plugindir_buffer, opt_plugin_dir, 0)) {
12932
1/2
✓ Branch 0 taken 442 times.
✗ Branch 1 not taken.
442 convert_dirname(plugindir_buffer, plugindir_buffer, NullS);
12933 442 opt_plugindir_len = strlen(plugindir_buffer);
12934
12935
1/2
✓ Branch 0 taken 442 times.
✗ Branch 1 not taken.
442 if (!case_insensitive_fs) {
12936
4/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 441 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 441 times.
442 if (!strncmp(plugindir_buffer, opt_var,
12937 opt_plugindir_len < opt_var_len ? opt_plugindir_len
12938 : opt_var_len)) {
12939 1 warn = true;
12940 1 strcpy(whichdir, "Plugin directory");
12941 }
12942 } else {
12943 if (!files_charset_info->coll->strnncoll(
12944 files_charset_info, (uchar *)plugindir_buffer, opt_plugindir_len,
12945 pointer_cast<const uchar *>(opt_var), opt_var_len, true)) {
12946 warn = true;
12947 strcpy(whichdir, "Plugin directory");
12948 }
12949 }
12950 }
12951
12952
2/2
✓ Branch 0 taken 8857 times.
✓ Branch 1 taken 441 times.
9298 if (warn)
12953
8/16
✓ Branch 0 taken 8857 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8857 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8857 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8857 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 8857 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 8857 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 8857 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 8857 times.
✗ Branch 15 not taken.
8857 LogErr(WARNING_LEVEL, ER_SEC_FILE_PRIV_DIRECTORY_INSECURE, variable_name,
12954 whichdir, variable_name);
12955
12956 #ifndef _WIN32
12957 /*
12958 Check for --secure-file-priv directory's permission
12959 */
12960
2/4
✓ Branch 0 taken 9298 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9298 times.
9298 if (!(my_stat(opt_var, &dir_stat, MYF(0)))) {
12961 LogErr(ERROR_LEVEL, ER_SEC_FILE_PRIV_CANT_STAT, variable_name);
12962 return false;
12963 }
12964
12965
1/2
✓ Branch 0 taken 9298 times.
✗ Branch 1 not taken.
9298 if (dir_stat.st_mode & S_IRWXO)
12966
8/16
✓ Branch 0 taken 9298 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9298 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9298 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 9298 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 9298 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 9298 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 9298 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 9298 times.
✗ Branch 15 not taken.
9298 LogErr(WARNING_LEVEL, ER_SEC_FILE_PRIV_DIRECTORY_PERMISSIONS,
12967 variable_name);
12968 #endif
12969 9298 return true;
12970 }
12971
12972 /**
12973 check_secure_file_priv_path : Checks path specified through
12974 --secure-file-priv and raises warning in following cases:
12975 1. If path is empty string or NULL and mysqld is not running
12976 with --initialize (bootstrap mode).
12977 2. If path can access data directory
12978 3. If path points to a directory which is accessible by
12979 all OS users (non-Windows build only)
12980
12981 It throws error in following cases:
12982
12983 1. If path normalization fails
12984 2. If it can not get stats of the directory
12985
12986 Assumptions :
12987 1. Data directory path has been normalized
12988 2. opt_secure_file_priv has been normalized unless it is set
12989 to "NULL".
12990
12991 @returns Status of validation
12992 @retval true : Validation is successful with/without warnings
12993 @retval false : Validation failed. Error is raised.
12994 */
12995
12996 9777 static bool check_secure_file_priv_path() {
12997 9777 return check_secure_path(opt_secure_file_priv, "secure-file-priv",
12998 9777 ER_SEC_FILE_PRIV_NULL);
12999 }
13000
13001 9777 static bool check_secure_log_path() {
13002 9777 return check_secure_path(opt_secure_log_path, "secure-log-path",
13003 9777 ER_SEC_LOG_PATH_NULL);
13004 }
13005
13006 #ifdef WIN32
13007 // check_tmpdir_path_lengths returns true if all paths are valid,
13008 // false if any path is too long.
13009 static bool check_tmpdir_path_lengths(const MY_TMPDIR &tmpdir_list) {
13010 const size_t max_tmpdir_len = MAX_PATH - MY_MAX_TEMP_FILENAME_LEN;
13011 bool result = true;
13012 for (uint i = 0; i <= tmpdir_list.max; i++) {
13013 std::string tmpdir_entry(tmpdir_list.list[i]);
13014 const int path_separator_reqd =
13015 is_directory_separator(tmpdir_entry.back()) ? 0 : 1;
13016 if ((tmpdir_entry.length() + path_separator_reqd) > max_tmpdir_len) {
13017 LogErr(ERROR_LEVEL, ER_TMPDIR_PATH_TOO_LONG, tmpdir_list.list[i],
13018 max_tmpdir_len, MY_MAX_TEMP_FILENAME_LEN);
13019 result = false;
13020 }
13021 }
13022 return result;
13023 }
13024 #endif
13025
13026 19555 static int fix_secure_path(const char *&opt_path, char *realpath,
13027 const char *variable_name) {
13028 19555 bool opt_nonempty = false;
13029 /*
13030 Convert the secure-file-priv/secure-log-path option to system format,
13031 allowing a quick strcmp to check if read or write is in an allowed dir
13032 */
13033
2/2
✓ Branch 0 taken 424 times.
✓ Branch 1 taken 19131 times.
19555 if (opt_initialize) opt_path = "";
13034 19555 opt_nonempty = opt_path[0] ? true : false;
13035
13036
3/4
✓ Branch 0 taken 9326 times.
✓ Branch 1 taken 10229 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9326 times.
19555 if (opt_nonempty && strlen(opt_path) > FN_REFLEN) {
13037 LogErr(WARNING_LEVEL, ER_SEC_FILE_PRIV_ARGUMENT_TOO_LONG, variable_name,
13038 FN_REFLEN - 1);
13039 return 1;
13040 }
13041
13042 19555 char buff[FN_REFLEN] = {
13043 0,
13044 };
13045
7/8
✓ Branch 0 taken 9326 times.
✓ Branch 1 taken 10229 times.
✓ Branch 2 taken 9326 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9299 times.
✓ Branch 5 taken 27 times.
✓ Branch 6 taken 9299 times.
✓ Branch 7 taken 10256 times.
19555 if (opt_nonempty && my_strcasecmp(system_charset_info, opt_path, "NULL")) {
13046
1/2
✓ Branch 0 taken 9299 times.
✗ Branch 1 not taken.
9299 int retval = my_realpath(buff, opt_path, MYF(MY_WME));
13047
2/2
✓ Branch 0 taken 9298 times.
✓ Branch 1 taken 1 times.
9299 if (!retval) {
13048
1/2
✓ Branch 0 taken 9298 times.
✗ Branch 1 not taken.
9298 convert_dirname(realpath, buff, NullS);
13049 #ifdef WIN32
13050 MY_DIR *dir = my_dir(realpath, MYF(MY_DONT_SORT + MY_WME));
13051 if (!dir) {
13052 retval = 1;
13053 } else {
13054 my_dirend(dir);
13055 }
13056 #endif
13057 }
13058
13059
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9298 times.
9299 if (retval) {
13060
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(ERROR_LEVEL, ER_SEC_FILE_PRIV_CANT_ACCESS_DIR, variable_name,
13061 opt_path);
13062 1 return 1;
13063 }
13064 9298 opt_path = realpath;
13065 }
13066
13067 19554 return 0;
13068 }
13069
13070 9793 static int fix_paths(void) {
13071 char buff[FN_REFLEN];
13072
1/2
✓ Branch 0 taken 9793 times.
✗ Branch 1 not taken.
9793 convert_dirname(mysql_home, mysql_home, NullS);
13073 /* Resolve symlinks to allow 'mysql_home' to be a relative symlink */
13074
1/2
✓ Branch 0 taken 9793 times.
✗ Branch 1 not taken.
9793 my_realpath(mysql_home, mysql_home, MYF(0));
13075 /* Ensure that mysql_home ends in FN_LIBCHAR */
13076 9793 char *pos = strend(mysql_home);
13077
3/4
✓ Branch 0 taken 9758 times.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 9758 times.
✗ Branch 3 not taken.
9793 if (pos == mysql_home || pos[-1] != FN_LIBCHAR) {
13078 9793 pos[0] = FN_LIBCHAR;
13079 9793 pos[1] = 0;
13080 }
13081
1/2
✓ Branch 0 taken 9793 times.
✗ Branch 1 not taken.
9793 convert_dirname(lc_messages_dir, lc_messages_dir, NullS);
13082
1/2
✓ Branch 0 taken 9793 times.
✗ Branch 1 not taken.
9793 convert_dirname(mysql_real_data_home, mysql_real_data_home, NullS);
13083
1/2
✓ Branch 0 taken 9793 times.
✗ Branch 1 not taken.
9793 (void)my_load_path(mysql_home, mysql_home, ""); // Resolve current dir
13084
1/2
✓ Branch 0 taken 9793 times.
✗ Branch 1 not taken.
9793 (void)my_load_path(mysql_real_data_home, mysql_real_data_home, mysql_home);
13085
1/2
✓ Branch 0 taken 9793 times.
✗ Branch 1 not taken.
9793 (void)my_load_path(pidfile_name, pidfile_name_ptr, mysql_real_data_home);
13086
13087
1/2
✓ Branch 0 taken 9793 times.
✗ Branch 1 not taken.
9793 convert_dirname(
13088 opt_plugin_dir,
13089
3/4
✓ Branch 0 taken 6176 times.
✓ Branch 1 taken 3617 times.
✓ Branch 2 taken 6176 times.
✗ Branch 3 not taken.
9793 opt_plugin_dir_ptr ? opt_plugin_dir_ptr : get_relative_path(PLUGINDIR),
13090 NullS);
13091
1/2
✓ Branch 0 taken 9793 times.
✗ Branch 1 not taken.
9793 (void)my_load_path(opt_plugin_dir, opt_plugin_dir, mysql_home);
13092 9793 opt_plugin_dir_ptr = opt_plugin_dir;
13093
13094
1/2
✓ Branch 0 taken 9793 times.
✗ Branch 1 not taken.
9793 my_realpath(mysql_unpacked_real_data_home, mysql_real_data_home, MYF(0));
13095 9793 mysql_unpacked_real_data_home_len = strlen(mysql_unpacked_real_data_home);
13096
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 9685 times.
9793 if (mysql_unpacked_real_data_home[mysql_unpacked_real_data_home_len - 1] ==
13097 FN_LIBCHAR)
13098 108 --mysql_unpacked_real_data_home_len;
13099
13100
1/2
✓ Branch 0 taken 9793 times.
✗ Branch 1 not taken.
9793 const char *sharedir = get_relative_path(SHAREDIR);
13101
2/4
✓ Branch 0 taken 9793 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9793 times.
9793 if (test_if_hard_path(sharedir))
13102 strmake(buff, sharedir, sizeof(buff) - 1); /* purecov: tested */
13103 else
13104
1/2
✓ Branch 0 taken 9793 times.
✗ Branch 1 not taken.
9793 strxnmov(buff, sizeof(buff) - 1, mysql_home, sharedir, NullS);
13105
1/2
✓ Branch 0 taken 9793 times.
✗ Branch 1 not taken.
9793 convert_dirname(buff, buff, NullS);
13106
1/2
✓ Branch 0 taken 9793 times.
✗ Branch 1 not taken.
9793 (void)my_load_path(lc_messages_dir, lc_messages_dir, buff);
13107
13108 /* If --character-sets-dir isn't given, use shared library dir */
13109
2/2
✓ Branch 0 taken 9404 times.
✓ Branch 1 taken 389 times.
9793 if (charsets_dir)
13110
1/2
✓ Branch 0 taken 9404 times.
✗ Branch 1 not taken.
9404 strmake(mysql_charsets_dir, charsets_dir, sizeof(mysql_charsets_dir) - 1);
13111 else
13112
1/2
✓ Branch 0 taken 389 times.
✗ Branch 1 not taken.
389 strxnmov(mysql_charsets_dir, sizeof(mysql_charsets_dir) - 1, buff,
13113 CHARSET_DIR, NullS);
13114
1/2
✓ Branch 0 taken 9793 times.
✗ Branch 1 not taken.
9793 (void)my_load_path(mysql_charsets_dir, mysql_charsets_dir, buff);
13115
1/2
✓ Branch 0 taken 9793 times.
✗ Branch 1 not taken.
9793 convert_dirname(mysql_charsets_dir, mysql_charsets_dir, NullS);
13116 9793 charsets_dir = mysql_charsets_dir;
13117
13118
3/4
✓ Branch 0 taken 9793 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 9791 times.
9793 if (init_tmpdir(&mysql_tmpdir_list, opt_mysql_tmpdir)) return 1;
13119 #ifdef WIN32
13120 if (!check_tmpdir_path_lengths(mysql_tmpdir_list)) return 1;
13121 #endif
13122
3/4
✓ Branch 0 taken 387 times.
✓ Branch 1 taken 9404 times.
✓ Branch 2 taken 387 times.
✗ Branch 3 not taken.
9791 if (!opt_mysql_tmpdir) opt_mysql_tmpdir = mysql_tmpdir;
13123
3/4
✓ Branch 0 taken 6790 times.
✓ Branch 1 taken 3001 times.
✓ Branch 2 taken 6790 times.
✗ Branch 3 not taken.
9791 if (!replica_load_tmpdir) replica_load_tmpdir = mysql_tmpdir;
13124
13125
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 9778 times.
9791 if (opt_help) return 0;
13126
13127
3/4
✓ Branch 0 taken 9778 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 9777 times.
9778 if (fix_secure_path(opt_secure_file_priv, secure_file_real_path,
13128 "secure-file-priv"))
13129 1 return 1;
13130
2/4
✓ Branch 0 taken 9777 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9777 times.
9777 if (!check_secure_file_priv_path()) return 1;
13131
13132
2/4
✓ Branch 0 taken 9777 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9777 times.
9777 if (fix_secure_path(opt_secure_log_path, secure_log_real_path,
13133 "secure-log-path"))
13134 return 1;
13135
2/4
✓ Branch 0 taken 9777 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9777 times.
9777 if (!check_secure_log_path()) return 1;
13136
13137 9777 return 0;
13138 }
13139
13140 /**
13141 Check if file system used for databases is case insensitive.
13142
13143 @param dir_name Directory to test
13144
13145 @retval
13146 -1 Don't know (Test failed)
13147 @retval
13148 0 File system is case sensitive
13149 @retval
13150 1 File system is case insensitive
13151 */
13152
13153 19074 static int test_if_case_insensitive(const char *dir_name) {
13154 19074 int result = 0;
13155 File file;
13156 char buff[FN_REFLEN], buff2[FN_REFLEN];
13157 MY_STAT stat_info;
13158 19074 const char *const tmp_file_name = "mysqld_tmp_file_case_insensitive_test";
13159
1/2
✓ Branch 0 taken 19074 times.
✗ Branch 1 not taken.
19074 DBUG_TRACE;
13160
13161
1/2
✓ Branch 0 taken 19074 times.
✗ Branch 1 not taken.
19074 fn_format(buff, tmp_file_name, dir_name, ".lower-test",
13162 MY_UNPACK_FILENAME | MY_REPLACE_EXT | MY_REPLACE_DIR);
13163
1/2
✓ Branch 0 taken 19074 times.
✗ Branch 1 not taken.
19074 fn_format(buff2, tmp_file_name, dir_name, ".LOWER-TEST",
13164 MY_UNPACK_FILENAME | MY_REPLACE_EXT | MY_REPLACE_DIR);
13165
1/2
✓ Branch 0 taken 19074 times.
✗ Branch 1 not taken.
19074 mysql_file_delete(key_file_casetest, buff2, MYF(0));
13166
1/2
✓ Branch 0 taken 19074 times.
✗ Branch 1 not taken.
19074 if ((file = mysql_file_create(key_file_casetest, buff, 0666, O_RDWR,
13167
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 19058 times.
19074 MYF(0))) < 0) {
13168
8/16
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 16 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 16 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 16 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 16 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 16 times.
✗ Branch 15 not taken.
16 LogErr(WARNING_LEVEL, ER_CANT_CREATE_TEST_FILE, buff);
13169 16 return -1;
13170 }
13171
1/2
✓ Branch 0 taken 19058 times.
✗ Branch 1 not taken.
19058 mysql_file_close(file, MYF(0));
13172
2/4
✓ Branch 0 taken 19058 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19058 times.
19058 if (mysql_file_stat(key_file_casetest, buff2, &stat_info, MYF(0)))
13173 result = 1; // Can access file
13174
1/2
✓ Branch 0 taken 19058 times.
✗ Branch 1 not taken.
19058 mysql_file_delete(key_file_casetest, buff, MYF(MY_WME));
13175
3/8
✓ Branch 0 taken 19058 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19058 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 19058 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
19058 DBUG_PRINT("exit", ("result: %d", result));
13176 19058 return result;
13177 19074 }
13178
13179 /**
13180 Create file to store pid number.
13181 */
13182 9218 static bool create_pid_file() {
13183 File file;
13184 9218 bool check_parent_path = true, is_path_accessible = true;
13185 9218 char pid_filepath[FN_REFLEN], *pos = nullptr;
13186 /* Copy pid file name to get pid file path */
13187 9218 strcpy(pid_filepath, pidfile_name);
13188
13189 /* Iterate through the entire path to check if even one of the sub-dirs
13190 is world-writable */
13191
7/8
✓ Branch 0 taken 92809 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 92809 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 83592 times.
✓ Branch 5 taken 9217 times.
✓ Branch 6 taken 83592 times.
✓ Branch 7 taken 9218 times.
92810 while (check_parent_path && (pos = strrchr(pid_filepath, FN_LIBCHAR)) &&
13192 (pos != pid_filepath)) /* shouldn't check root */
13193 {
13194 83592 *pos = '\0'; /* Trim the inner-most dir */
13195
3/7
✓ Branch 0 taken 83592 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 83591 times.
✗ Branch 6 not taken.
83592 switch (is_file_or_dir_world_writable(pid_filepath)) {
13196 case -2:
13197 is_path_accessible = false;
13198 break;
13199 case -1:
13200 LogErr(ERROR_LEVEL, ER_CANT_CHECK_PID_PATH, strerror(errno));
13201 exit(MYSQLD_ABORT_EXIT);
13202 1 case 1:
13203
8/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
1 LogErr(WARNING_LEVEL, ER_PID_FILE_PRIV_DIRECTORY_INSECURE,
13204 pid_filepath);
13205 1 check_parent_path = false;
13206 1 break;
13207 83591 case 0:
13208 83591 continue; /* Keep checking the parent dir */
13209 }
13210 }
13211
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9218 times.
9218 if (!is_path_accessible) {
13212 LogErr(WARNING_LEVEL, ER_PID_FILEPATH_LOCATIONS_INACCESSIBLE);
13213 }
13214
1/2
✓ Branch 0 taken 9218 times.
✗ Branch 1 not taken.
9218 if ((file = mysql_file_create(key_file_pid, pidfile_name, 0664,
13215
1/2
✓ Branch 0 taken 9218 times.
✗ Branch 1 not taken.
9218 O_WRONLY | O_TRUNC, MYF(MY_WME))) >= 0) {
13216 char buff[MAX_BIGINT_WIDTH + 1], *end;
13217
1/2
✓ Branch 0 taken 9218 times.
✗ Branch 1 not taken.
9218 end = longlong10_to_str(getpid(), buff, -10);
13218 9218 *end++ = '\n';
13219
2/4
✓ Branch 0 taken 9218 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9218 times.
✗ Branch 3 not taken.
9218 if (!mysql_file_write(file, (uchar *)buff, (uint)(end - buff),
13220 MYF(MY_WME | MY_NABP))) {
13221
1/2
✓ Branch 0 taken 9218 times.
✗ Branch 1 not taken.
9218 mysql_file_close(file, MYF(0));
13222 9218 pid_file_created = true;
13223 9218 return false;
13224 }
13225 mysql_file_close(file, MYF(0));
13226 }
13227 LogErr(ERROR_LEVEL, ER_CANT_CREATE_PID_FILE, strerror(errno));
13228 return true;
13229 }
13230
13231 /**
13232 Remove the process' pid file.
13233
13234 @param flags file operation flags
13235 */
13236
13237 8493 static void delete_pid_file(myf flags) {
13238 File file;
13239
6/6
✓ Branch 0 taken 8276 times.
✓ Branch 1 taken 217 times.
✓ Branch 2 taken 7869 times.
✓ Branch 3 taken 407 times.
✓ Branch 4 taken 624 times.
✓ Branch 5 taken 7869 times.
16362 if (opt_initialize || !pid_file_created ||
13240
2/4
✓ Branch 0 taken 7869 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7869 times.
7869 !(file = mysql_file_open(key_file_pid, pidfile_name, O_RDONLY, flags)))
13241 624 return;
13242
13243
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7869 times.
7869 if (file == -1) {
13244 LogErr(INFORMATION_LEVEL, ER_CANT_REMOVE_PID_FILE, strerror(errno));
13245 return;
13246 }
13247
13248 uchar buff[MAX_BIGINT_WIDTH + 1];
13249 /* Make sure that the pid file was created by the same process. */
13250
1/2
✓ Branch 0 taken 7869 times.
✗ Branch 1 not taken.
7869 size_t error = mysql_file_read(file, buff, sizeof(buff), flags);
13251
1/2
✓ Branch 0 taken 7869 times.
✗ Branch 1 not taken.
7869 mysql_file_close(file, flags);
13252 7869 buff[sizeof(buff) - 1] = '\0';
13253
3/6
✓ Branch 0 taken 7869 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7869 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7869 times.
✗ Branch 5 not taken.
7869 if (error != MY_FILE_ERROR && atol((char *)buff) == (long)getpid()) {
13254
1/2
✓ Branch 0 taken 7869 times.
✗ Branch 1 not taken.
7869 mysql_file_delete(key_file_pid, pidfile_name, flags);
13255 7869 pid_file_created = false;
13256 }
13257 7869 return;
13258 }
13259
13260 /**
13261 Delete mysql.ibd after aborting upgrade.
13262 */
13263 22 static void delete_dictionary_tablespace() {
13264 char path[FN_REFLEN + 1];
13265 bool not_used;
13266
13267
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 build_table_filename(path, sizeof(path) - 1, "", "mysql", ".ibd", 0,
13268 &not_used);
13269
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 (void)mysql_file_delete(key_file_misc, path, MYF(MY_WME));
13270
13271 // Drop file which tracks progress of upgrade.
13272
2/4
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
22 dd::upgrade_57::Upgrade_status().remove();
13273 22 }
13274
13275 /**
13276 Returns the current state of the server : booting, operational or shutting
13277 down.
13278
13279 @return
13280 SERVER_BOOTING Server is not operational. It is starting.
13281 SERVER_OPERATING Server is fully initialized and operating.
13282 SERVER_SHUTTING_DOWN Server is shutting down.
13283 */
13284 154218 enum_server_operational_state get_server_state() {
13285 154218 return server_operational_state;
13286 }
13287
13288 /**
13289 Reset status for all threads.
13290 */
13291 class Reset_thd_status : public Do_THD_Impl {
13292 public:
13293 4105 Reset_thd_status() = default;
13294 13012 void operator()(THD *thd) override {
13295 /* Update the global status if not done so already. */
13296
1/2
✓ Branch 0 taken 13012 times.
✗ Branch 1 not taken.
13012 if (!thd->status_var_aggregated) {
13297 13012 add_to_status(&global_status_var, &thd->status_var);
13298 }
13299 13012 reset_system_status_vars(&thd->status_var);
13300 13012 }
13301 };
13302
13303 /**
13304 Reset global and session status variables.
13305 */
13306 4105 void refresh_status() {
13307
1/2
✓ Branch 0 taken 4105 times.
✗ Branch 1 not taken.
4105 mysql_mutex_lock(&LOCK_status);
13308
13309 /* For all threads, add status to global status and then reset. */
13310
1/2
✓ Branch 0 taken 4105 times.
✗ Branch 1 not taken.
4105 Reset_thd_status reset_thd_status;
13311
1/2
✓ Branch 0 taken 4105 times.
✗ Branch 1 not taken.
4105 Global_THD_manager::get_instance()->do_for_all_thd_copy(&reset_thd_status);
13312 /* net_buffer_length does not accumulate the historical values */
13313 4105 global_status_var.net_buffer_length = 0ULL;
13314 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
13315 /* Reset aggregated status counters. */
13316
1/2
✓ Branch 0 taken 4105 times.
✗ Branch 1 not taken.
4105 reset_pfs_status_stats();
13317 #endif
13318
13319 /* Reset some global variables. */
13320
1/2
✓ Branch 0 taken 4105 times.
✗ Branch 1 not taken.
4105 reset_status_vars();
13321 #ifdef WITH_WSREP
13322
3/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4097 times.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
4105 if (WSREP_ON) {
13323
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
8 Wsrep_server_state::instance().provider().reset_status();
13324 }
13325 #endif /* WITH_WSREP */
13326
13327 /* Reset the counters of all key caches (default and named). */
13328
1/2
✓ Branch 0 taken 4105 times.
✗ Branch 1 not taken.
4105 process_key_caches(reset_key_cache_counters);
13329 4105 flush_status_time = time((time_t *)nullptr);
13330
1/2
✓ Branch 0 taken 4105 times.
✗ Branch 1 not taken.
4105 mysql_mutex_unlock(&LOCK_status);
13331
13332 /*
13333 Set max_used_connections to the number of currently open
13334 connections. Do this out of LOCK_status to avoid deadlocks.
13335 Status reset becomes not atomic, but status data is not exact anyway.
13336 */
13337
1/2
✓ Branch 0 taken 4105 times.
✗ Branch 1 not taken.
4105 Connection_handler_manager::reset_max_used_connections();
13338 4105 }
13339
13340 class Do_THD_reset_status : public Do_THD_Impl {
13341 public:
13342 582 Do_THD_reset_status() {}
13343 1273 void operator()(THD *thd) override {
13344 1273 PSI_thread *thread = thd->get_psi();
13345
2/2
✓ Branch 0 taken 691 times.
✓ Branch 1 taken 582 times.
1273 if (thread != nullptr) {
13346 /*
13347 During this call,
13348 - inspecting the THD associated with the performance schema
13349 thread instrumentation,
13350 - inspecting the THD status variable
13351 is safe, because the call is protected
13352 by Global_THD_manager::do_for_all_thd(),
13353 so the THD will not be destroyed during the iteration.
13354 */
13355 691 PSI_THREAD_CALL(aggregate_thread_status)(thread);
13356 }
13357 1273 }
13358 };
13359
13360 582 void reset_status_by_thd() {
13361
1/2
✓ Branch 0 taken 582 times.
✗ Branch 1 not taken.
582 Do_THD_reset_status doit;
13362
1/2
✓ Branch 0 taken 582 times.
✗ Branch 1 not taken.
582 Global_THD_manager::get_instance()->do_for_all_thd(&doit);
13363 582 }
13364
13365 /*****************************************************************************
13366 Instantiate variables for missing storage engines
13367 This section should go away soon
13368 *****************************************************************************/
13369
13370 #ifdef HAVE_PSI_INTERFACE
13371 PSI_mutex_key key_LOCK_tc;
13372 PSI_mutex_key key_hash_filo_lock;
13373 PSI_mutex_key key_LOCK_error_log;
13374 PSI_mutex_key key_LOCK_thd_data;
13375 PSI_mutex_key key_LOCK_thd_sysvar;
13376 PSI_mutex_key key_LOCK_thd_protocol;
13377 PSI_mutex_key key_LOCK_thd_security_ctx;
13378 PSI_mutex_key key_LOG_LOCK_log;
13379 PSI_mutex_key key_source_info_data_lock;
13380 PSI_mutex_key key_source_info_run_lock;
13381 PSI_mutex_key key_source_info_sleep_lock;
13382 PSI_mutex_key key_source_info_thd_lock;
13383 PSI_mutex_key key_source_info_rotate_lock;
13384 PSI_mutex_key key_mutex_replica_reporting_capability_err_lock;
13385 PSI_mutex_key key_relay_log_info_data_lock;
13386 PSI_mutex_key key_relay_log_info_sleep_lock;
13387 PSI_mutex_key key_relay_log_info_thd_lock;
13388 PSI_mutex_key key_relay_log_info_log_space_lock;
13389 PSI_mutex_key key_relay_log_info_run_lock;
13390 PSI_mutex_key key_mutex_slave_parallel_pend_jobs;
13391 PSI_mutex_key key_mutex_slave_parallel_worker_count;
13392 PSI_mutex_key key_mutex_slave_parallel_worker;
13393 PSI_mutex_key key_structure_guard_mutex;
13394 PSI_mutex_key key_TABLE_SHARE_LOCK_ha_data;
13395 PSI_mutex_key key_LOCK_query_plan;
13396 PSI_mutex_key key_LOCK_thd_query;
13397 PSI_mutex_key key_LOCK_cost_const;
13398 PSI_mutex_key key_LOCK_current_cond;
13399 PSI_mutex_key key_LOCK_temporary_tables;
13400 PSI_mutex_key key_LOCK_global_user_client_stats;
13401 PSI_mutex_key key_LOCK_global_table_stats;
13402 PSI_mutex_key key_LOCK_global_index_stats;
13403 PSI_mutex_key key_RELAYLOG_LOCK_commit;
13404 PSI_mutex_key key_RELAYLOG_LOCK_index;
13405 PSI_mutex_key key_RELAYLOG_LOCK_log;
13406 PSI_mutex_key key_RELAYLOG_LOCK_log_end_pos;
13407 PSI_mutex_key key_RELAYLOG_LOCK_sync;
13408 PSI_mutex_key key_RELAYLOG_LOCK_xids;
13409 PSI_mutex_key key_gtid_ensure_index_mutex;
13410 PSI_mutex_key key_object_cache_mutex; // TODO need to initialize
13411 PSI_cond_key key_object_loading_cond; // TODO need to initialize
13412 PSI_mutex_key key_mta_temp_table_LOCK;
13413 PSI_mutex_key key_mta_gaq_LOCK;
13414 PSI_mutex_key key_thd_timer_mutex;
13415 PSI_mutex_key key_commit_order_manager_mutex;
13416 PSI_mutex_key key_mutex_replica_worker_hash;
13417 PSI_mutex_key key_monitor_info_run_lock;
13418 PSI_mutex_key key_LOCK_delegate_connection_mutex;
13419 PSI_mutex_key key_LOCK_group_replication_connection_mutex;
13420
13421 #ifdef WITH_WSREP
13422 PSI_mutex_key key_LOCK_wsrep_ready;
13423 PSI_mutex_key key_LOCK_wsrep_sst;
13424 PSI_mutex_key key_LOCK_wsrep_sst_init;
13425 PSI_mutex_key key_LOCK_wsrep_replaying;
13426
13427 PSI_mutex_key key_LOCK_wsrep_slave_threads;
13428 PSI_mutex_key key_LOCK_wsrep_cluster_config;
13429 PSI_mutex_key key_LOCK_wsrep_desync;
13430
13431 PSI_mutex_key key_LOCK_wsrep_group_commit;
13432 PSI_mutex_key key_LOCK_wsrep_SR_pool;
13433 PSI_mutex_key key_LOCK_wsrep_SR_store;
13434
13435 PSI_mutex_key key_LOCK_wsrep_thd;
13436 PSI_mutex_key key_LOCK_wsrep_thd_attachable_trx;
13437 PSI_mutex_key key_LOCK_wsrep_sst_thread;
13438
13439 PSI_mutex_key key_LOCK_wsrep_thd_queue;
13440
13441 PSI_mutex_key key_LOCK_wsrep_alter_tablespace;
13442 #endif /* WITH_WSREP */
13443
13444 /* clang-format off */
13445 static PSI_mutex_info all_server_mutexes[]=
13446 {
13447 { &key_LOCK_tc, "TC_LOG_MMAP::LOCK_tc", 0, 0, PSI_DOCUMENT_ME},
13448 { &key_BINLOG_LOCK_commit, "MYSQL_BIN_LOG::LOCK_commit", 0, 0, PSI_DOCUMENT_ME},
13449 { &key_BINLOG_LOCK_commit_queue, "MYSQL_BIN_LOG::LOCK_commit_queue", 0, 0, PSI_DOCUMENT_ME},
13450 { &key_BINLOG_LOCK_done, "MYSQL_BIN_LOG::LOCK_done", 0, 0, PSI_DOCUMENT_ME},
13451 { &key_BINLOG_LOCK_flush_queue, "MYSQL_BIN_LOG::LOCK_flush_queue", 0, 0, PSI_DOCUMENT_ME},
13452 { &key_BINLOG_LOCK_index, "MYSQL_BIN_LOG::LOCK_index", 0, 0, PSI_DOCUMENT_ME},
13453 { &key_BINLOG_LOCK_log, "MYSQL_BIN_LOG::LOCK_log", 0, 0, PSI_DOCUMENT_ME},
13454 { &key_BINLOG_LOCK_binlog_end_pos, "MYSQL_BIN_LOG::LOCK_binlog_end_pos", 0, 0, PSI_DOCUMENT_ME},
13455 { &key_BINLOG_LOCK_sync, "MYSQL_BIN_LOG::LOCK_sync", 0, 0, PSI_DOCUMENT_ME},
13456 { &key_BINLOG_LOCK_sync_queue, "MYSQL_BIN_LOG::LOCK_sync_queue", 0, 0, PSI_DOCUMENT_ME},
13457 { &key_BINLOG_LOCK_xids, "MYSQL_BIN_LOG::LOCK_xids", 0, 0, PSI_DOCUMENT_ME},
13458 { &key_RELAYLOG_LOCK_commit, "MYSQL_RELAY_LOG::LOCK_commit", 0, 0, PSI_DOCUMENT_ME},
13459 { &key_RELAYLOG_LOCK_index, "MYSQL_RELAY_LOG::LOCK_index", 0, 0, PSI_DOCUMENT_ME},
13460 { &key_RELAYLOG_LOCK_log, "MYSQL_RELAY_LOG::LOCK_log", 0, 0, PSI_DOCUMENT_ME},
13461 { &key_RELAYLOG_LOCK_log_end_pos, "MYSQL_RELAY_LOG::LOCK_log_end_pos", 0, 0, PSI_DOCUMENT_ME},
13462 { &key_RELAYLOG_LOCK_sync, "MYSQL_RELAY_LOG::LOCK_sync", 0, 0, PSI_DOCUMENT_ME},
13463 { &key_RELAYLOG_LOCK_xids, "MYSQL_RELAY_LOG::LOCK_xids", 0, 0, PSI_DOCUMENT_ME},
13464 { &key_hash_filo_lock, "hash_filo::lock", 0, 0, PSI_DOCUMENT_ME},
13465 { &Gtid_set::key_gtid_executed_free_intervals_mutex, "Gtid_set::gtid_executed::free_intervals_mutex", 0, 0, PSI_DOCUMENT_ME},
13466 { &key_LOCK_bloom_filter, "Bloom_filter", 0, 0, PSI_DOCUMENT_ME},
13467 { &key_LOCK_crypt, "LOCK_crypt", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13468 { &key_LOCK_error_log, "LOCK_error_log", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13469 { &key_LOCK_global_system_variables, "LOCK_global_system_variables", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13470 #if defined(_WIN32)
13471 { &key_LOCK_handler_count, "LOCK_handler_count", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13472 { &key_LOCK_global_user_client_stats,
13473 "LOCK_global_user_client_stats", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13474 { &key_LOCK_global_table_stats,
13475 "LOCK_global_table_stats", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13476 { &key_LOCK_global_index_stats,
13477 "LOCK_global_index_stats", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13478 #endif
13479 { &key_LOCK_manager, "LOCK_manager", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13480 { &key_LOCK_prepared_stmt_count, "LOCK_prepared_stmt_count", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13481 { &key_LOCK_replica_list, "LOCK_replica_list", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13482 { &key_LOCK_sql_replica_skip_counter, "LOCK_sql_replica_skip_counter", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13483 { &key_LOCK_replica_net_timeout, "LOCK_replica_net_timeout", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13484 { &key_LOCK_replica_trans_dep_tracker, "LOCK_replica_trans_dep_tracker", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13485 { &key_LOCK_server_started, "LOCK_server_started", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13486 #if !defined(_WIN32)
13487 { &key_LOCK_socket_listener_active, "LOCK_socket_listener_active", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13488 { &key_LOCK_start_signal_handler, "LOCK_start_signal_handler", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13489 #endif
13490 { &key_LOCK_status, "LOCK_status", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13491 { &key_LOCK_thd_data, "THD::LOCK_thd_data", 0, PSI_VOLATILITY_SESSION, PSI_DOCUMENT_ME},
13492 { &key_LOCK_thd_query, "THD::LOCK_thd_query", 0, PSI_VOLATILITY_SESSION, PSI_DOCUMENT_ME},
13493 { &key_LOCK_thd_sysvar, "THD::LOCK_thd_sysvar", 0, PSI_VOLATILITY_SESSION, PSI_DOCUMENT_ME},
13494 { &key_LOCK_thd_protocol, "THD::LOCK_thd_protocol", 0, PSI_VOLATILITY_SESSION, PSI_DOCUMENT_ME},
13495 { &key_LOCK_thd_security_ctx, "THD::LOCK_thd_security_ctx", 0, PSI_VOLATILITY_SESSION, "A lock to control access to a THD's security context"},
13496 { &key_LOCK_user_conn, "LOCK_user_conn", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13497 { &key_LOCK_uuid_generator, "LOCK_uuid_generator", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13498 { &key_LOCK_sql_rand, "LOCK_sql_rand", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13499 { &key_LOG_LOCK_log, "LOG::LOCK_log", 0, 0, PSI_DOCUMENT_ME},
13500 { &key_source_info_data_lock, "Source_info::data_lock", 0, 0, PSI_DOCUMENT_ME},
13501 { &key_source_info_run_lock, "Source_info::run_lock", 0, 0, PSI_DOCUMENT_ME},
13502 { &key_source_info_sleep_lock, "Source_info::sleep_lock", 0, 0, PSI_DOCUMENT_ME},
13503 { &key_source_info_thd_lock, "Source_info::info_thd_lock", 0, 0, PSI_DOCUMENT_ME},
13504 { &key_source_info_rotate_lock, "Source_info::rotate_lock", 0, 0, PSI_DOCUMENT_ME},
13505 { &key_mutex_replica_reporting_capability_err_lock, "Replica_reporting_capability::err_lock", 0, 0, PSI_DOCUMENT_ME},
13506 { &key_relay_log_info_data_lock, "Relay_log_info::data_lock", 0, 0, PSI_DOCUMENT_ME},
13507 { &key_relay_log_info_sleep_lock, "Relay_log_info::sleep_lock", 0, 0, PSI_DOCUMENT_ME},
13508 { &key_relay_log_info_thd_lock, "Relay_log_info::info_thd_lock", 0, 0, PSI_DOCUMENT_ME},
13509 { &key_relay_log_info_log_space_lock, "Relay_log_info::log_space_lock", 0, 0, PSI_DOCUMENT_ME},
13510 { &key_relay_log_info_run_lock, "Relay_log_info::run_lock", 0, 0, PSI_DOCUMENT_ME},
13511 { &key_mutex_slave_parallel_pend_jobs, "Relay_log_info::pending_jobs_lock", 0, 0, PSI_DOCUMENT_ME},
13512 { &key_mutex_slave_parallel_worker_count, "Relay_log_info::exit_count_lock", 0, 0, PSI_DOCUMENT_ME},
13513 { &key_mutex_slave_parallel_worker, "Worker_info::jobs_lock", 0, 0, PSI_DOCUMENT_ME},
13514 { &key_TABLE_SHARE_LOCK_ha_data, "TABLE_SHARE::LOCK_ha_data", 0, 0, PSI_DOCUMENT_ME},
13515 { &key_LOCK_error_messages, "LOCK_error_messages", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13516 { &key_LOCK_log_throttle_qni, "LOCK_log_throttle_qni", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13517 { &key_gtid_ensure_index_mutex, "Gtid_state", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13518 { &key_LOCK_query_plan, "THD::LOCK_query_plan", 0, PSI_VOLATILITY_SESSION, PSI_DOCUMENT_ME},
13519 { &key_LOCK_cost_const, "Cost_constant_cache::LOCK_cost_const", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13520 { &key_LOCK_current_cond, "THD::LOCK_current_cond", 0, PSI_VOLATILITY_SESSION, PSI_DOCUMENT_ME},
13521 { &key_mta_temp_table_LOCK, "key_mta_temp_table_LOCK", 0, 0, PSI_DOCUMENT_ME},
13522 { &key_LOCK_reset_gtid_table, "LOCK_reset_gtid_table", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13523 { &key_LOCK_compress_gtid_table, "LOCK_compress_gtid_table", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13524 { &key_LOCK_collect_instance_log, "LOCK_collect_instance_log", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13525 { &key_mta_gaq_LOCK, "key_mta_gaq_LOCK", 0, 0, PSI_DOCUMENT_ME},
13526 { &key_thd_timer_mutex, "thd_timer_mutex", 0, 0, PSI_DOCUMENT_ME},
13527 { &key_commit_order_manager_mutex, "Commit_order_manager::m_mutex", 0, 0, PSI_DOCUMENT_ME},
13528 { &key_mutex_replica_worker_hash, "Relay_log_info::replica_worker_hash_lock", 0, 0, PSI_DOCUMENT_ME},
13529 { &key_LOCK_default_password_lifetime, "LOCK_default_password_lifetime", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13530 { &key_LOCK_mandatory_roles, "LOCK_mandatory_roles", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13531 { &key_LOCK_password_history, "LOCK_password_history", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13532 { &key_LOCK_password_reuse_interval, "LOCK_password_reuse_interval", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13533 { &key_LOCK_keyring_operations, "LOCK_keyring_operations", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13534 { &key_LOCK_tls_ctx_options, "LOCK_tls_ctx_options", 0, 0, "A lock to control all of the --ssl-* CTX related command line options for client server connection port"},
13535 { &key_LOCK_admin_tls_ctx_options, "LOCK_admin_tls_ctx_options", 0, 0, "A lock to control all of the --ssl-* CTX related command line options for administrative connection port"},
13536 { &key_LOCK_rotate_binlog_master_key, "LOCK_rotate_binlog_master_key", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13537 { &key_monitor_info_run_lock, "Source_IO_monitor::run_lock", 0, 0, PSI_DOCUMENT_ME},
13538 { &key_LOCK_delegate_connection_mutex, "LOCK_delegate_connection_mutex", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13539 { &key_LOCK_group_replication_connection_mutex, "LOCK_group_replication_connection_mutex", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13540 { &key_LOCK_authentication_policy, "LOCK_authentication_policy", PSI_FLAG_SINGLETON, 0, "A lock to ensure execution of CREATE USER or ALTER USER sql and SET @@global.authentication_policy variable are serialized"},
13541 { &key_LOCK_global_conn_mem_limit, "LOCK_global_conn_mem_limit", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME}
13542 #ifdef WITH_WSREP
13543 ,
13544 { &key_LOCK_wsrep_ready, "LOCK_wsrep_ready", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13545 { &key_LOCK_wsrep_sst, "LOCK_wsrep_sst", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13546 { &key_LOCK_wsrep_sst_init, "LOCK_wsrep_sst_init", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13547 { &key_LOCK_wsrep_replaying, "LOCK_wsrep_replaying", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13548
13549 { &key_LOCK_wsrep_slave_threads, "LOCK_wsrep_slave_threads", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13550 { &key_LOCK_wsrep_cluster_config, "LOCK_wsrep_cluster_config", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13551 { &key_LOCK_wsrep_desync, "LOCK_wsrep_desync", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13552
13553 { &key_LOCK_wsrep_group_commit, "LOCK_wsrep_group_commit", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13554 { &key_LOCK_wsrep_SR_pool, "LOCK_wsrep_SR_pool", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13555 { &key_LOCK_wsrep_SR_store, "LOCK_wsrep_SR_store", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13556
13557 { &key_LOCK_wsrep_thd, "LOCK_wsrep_thd", 0, 0, PSI_DOCUMENT_ME},
13558 { &key_LOCK_wsrep_thd_attachable_trx, "LOCK_wsrep_thd_attachable_trx", 0, 0, PSI_DOCUMENT_ME},
13559 { &key_LOCK_wsrep_sst_thread, "LOCK_wsrep_sst_thread", 0, 0, PSI_DOCUMENT_ME},
13560
13561 { &key_LOCK_wsrep_thd_queue, "LOCK_wsrep_thd_queue", 0, 0, PSI_DOCUMENT_ME},
13562 { &key_LOCK_wsrep_alter_tablespace, "LOCK_wsrep_alter_tablespace", 0, 0, PSI_DOCUMENT_ME}
13563 #endif /* WITH_WSREP */
13564 };
13565 /* clang-format on */
13566
13567 PSI_rwlock_key key_rwlock_LOCK_logger;
13568 PSI_rwlock_key key_rwlock_channel_map_lock;
13569 PSI_rwlock_key key_rwlock_channel_lock;
13570 PSI_rwlock_key key_rwlock_receiver_sid_lock;
13571 PSI_rwlock_key key_rwlock_rpl_filter_lock;
13572 PSI_rwlock_key key_rwlock_channel_to_filter_lock;
13573 PSI_rwlock_key key_rwlock_LOCK_consistent_snapshot;
13574 PSI_rwlock_key key_rwlock_Trans_delegate_lock;
13575 PSI_rwlock_key key_rwlock_Server_state_delegate_lock;
13576 PSI_rwlock_key key_rwlock_Binlog_storage_delegate_lock;
13577 PSI_rwlock_key key_rwlock_Binlog_transmit_delegate_lock;
13578 PSI_rwlock_key key_rwlock_Binlog_relay_IO_delegate_lock;
13579 PSI_rwlock_key key_rwlock_resource_group_mgr_map_lock;
13580
13581 /* clang-format off */
13582 static PSI_rwlock_info all_server_rwlocks[]=
13583 {
13584 { &key_rwlock_Binlog_transmit_delegate_lock, "Binlog_transmit_delegate::lock", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13585 { &key_rwlock_Binlog_relay_IO_delegate_lock, "Binlog_relay_IO_delegate::lock", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13586 { &key_rwlock_LOCK_logger, "LOGGER::LOCK_logger", 0, 0, PSI_DOCUMENT_ME},
13587 { &key_rwlock_LOCK_sys_init_connect, "LOCK_sys_init_connect", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13588 { &key_rwlock_LOCK_sys_init_replica, "LOCK_sys_init_replica", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13589 { &key_rwlock_LOCK_system_variables_hash, "LOCK_system_variables_hash", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13590 { &key_rwlock_global_sid_lock, "gtid_commit_rollback", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13591 { &key_rwlock_gtid_mode_lock, "gtid_mode_lock", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13592 { &key_rwlock_channel_map_lock, "channel_map_lock", 0, 0, PSI_DOCUMENT_ME},
13593 { &key_rwlock_channel_lock, "channel_lock", 0, 0, PSI_DOCUMENT_ME},
13594 { &key_rwlock_Trans_delegate_lock, "Trans_delegate::lock", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13595 { &key_rwlock_Server_state_delegate_lock, "Server_state_delegate::lock", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13596 { &key_rwlock_Binlog_storage_delegate_lock, "Binlog_storage_delegate::lock", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13597 { &key_rwlock_receiver_sid_lock, "gtid_retrieved", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13598 { &key_rwlock_rpl_filter_lock, "rpl_filter_lock", 0, 0, PSI_DOCUMENT_ME},
13599 { &key_rwlock_channel_to_filter_lock, "channel_to_filter_lock", 0, 0, PSI_DOCUMENT_ME},
13600 { &key_rwlock_resource_group_mgr_map_lock, "Resource_group_mgr::m_map_rwlock", 0, 0, PSI_DOCUMENT_ME},
13601 #ifdef _WIN32
13602 { &key_rwlock_LOCK_named_pipe_full_access_group, "LOCK_named_pipe_full_access_group", PSI_FLAG_SINGLETON, 0,
13603 "This lock protects named pipe security attributes, preventing their "
13604 "simultaneous application and modification."},
13605 #endif // _WIN32
13606 { &key_rwlock_LOCK_consistent_snapshot, "LOCK_consistent_snapshot", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME}
13607 };
13608 /* clang-format on */
13609
13610 PSI_cond_key key_PAGE_cond;
13611 PSI_cond_key key_COND_active;
13612 PSI_cond_key key_COND_pool;
13613 PSI_cond_key key_COND_cache_status_changed;
13614 PSI_cond_key key_item_func_sleep_cond;
13615 PSI_cond_key key_source_info_data_cond;
13616 PSI_cond_key key_source_info_start_cond;
13617 PSI_cond_key key_source_info_stop_cond;
13618 PSI_cond_key key_source_info_sleep_cond;
13619 PSI_cond_key key_source_info_rotate_cond;
13620 PSI_cond_key key_relay_log_info_data_cond;
13621 PSI_cond_key key_relay_log_info_log_space_cond;
13622 PSI_cond_key key_relay_log_info_start_cond;
13623 PSI_cond_key key_relay_log_info_stop_cond;
13624 PSI_cond_key key_relay_log_info_sleep_cond;
13625 PSI_cond_key key_cond_slave_parallel_pend_jobs;
13626 PSI_cond_key key_cond_slave_parallel_worker;
13627 PSI_cond_key key_cond_mta_gaq;
13628
13629 #ifdef WITH_WSREP
13630 PSI_cond_key key_COND_wsrep_ready;
13631 PSI_cond_key key_COND_wsrep_sst;
13632 PSI_cond_key key_COND_wsrep_sst_init;
13633 PSI_cond_key key_COND_wsrep_replaying;
13634 PSI_cond_key key_COND_wsrep_slave_threads;
13635
13636 PSI_cond_key key_COND_wsrep_thd;
13637 PSI_cond_key key_COND_wsrep_sst_thread;
13638
13639 PSI_cond_key key_COND_wsrep_thd_queue;
13640 PSI_cond_key key_COND_wsrep_group_commit;
13641 #endif /* WITH_WSREP */
13642
13643 PSI_cond_key key_RELAYLOG_update_cond;
13644 PSI_cond_key key_gtid_ensure_index_cond;
13645 PSI_cond_key key_COND_thr_lock;
13646 PSI_cond_key key_commit_order_manager_cond;
13647 PSI_cond_key key_cond_slave_worker_hash;
13648 PSI_cond_key key_monitor_info_run_cond;
13649 PSI_cond_key key_COND_delegate_connection_cond_var;
13650 PSI_cond_key key_COND_group_replication_connection_cond_var;
13651
13652 /* clang-format off */
13653 static PSI_cond_info all_server_conds[]=
13654 {
13655 { &key_PAGE_cond, "PAGE::cond", 0, 0, PSI_DOCUMENT_ME},
13656 { &key_COND_active, "TC_LOG_MMAP::COND_active", 0, 0, PSI_DOCUMENT_ME},
13657 { &key_COND_pool, "TC_LOG_MMAP::COND_pool", 0, 0, PSI_DOCUMENT_ME},
13658 { &key_BINLOG_COND_done, "MYSQL_BIN_LOG::COND_done", 0, 0, PSI_DOCUMENT_ME},
13659 { &key_BINLOG_COND_flush_queue, "MYSQL_BIN_LOG::COND_flush_queue", 0, 0, PSI_DOCUMENT_ME},
13660 { &key_BINLOG_update_cond, "MYSQL_BIN_LOG::update_cond", 0, 0, PSI_DOCUMENT_ME},
13661 { &key_BINLOG_prep_xids_cond, "MYSQL_BIN_LOG::prep_xids_cond", 0, 0, PSI_DOCUMENT_ME},
13662 { &key_RELAYLOG_update_cond, "MYSQL_RELAY_LOG::update_cond", 0, 0, PSI_DOCUMENT_ME},
13663 #if defined(_WIN32)
13664 { &key_COND_handler_count, "COND_handler_count", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13665 #endif
13666 { &key_COND_manager, "COND_manager", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13667 { &key_COND_server_started, "COND_server_started", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13668 #if !defined(_WIN32)
13669 { &key_COND_socket_listener_active, "COND_socket_listener_active", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13670 { &key_COND_start_signal_handler, "COND_start_signal_handler", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13671 #endif
13672 { &key_COND_thr_lock, "COND_thr_lock", 0, 0, PSI_DOCUMENT_ME},
13673 { &key_item_func_sleep_cond, "Item_func_sleep::cond", 0, 0, PSI_DOCUMENT_ME},
13674 { &key_source_info_data_cond, "Source_info::data_cond", 0, 0, PSI_DOCUMENT_ME},
13675 { &key_source_info_start_cond, "Source_info::start_cond", 0, 0, PSI_DOCUMENT_ME},
13676 { &key_source_info_stop_cond, "Source_info::stop_cond", 0, 0, PSI_DOCUMENT_ME},
13677 { &key_source_info_sleep_cond, "Source_info::sleep_cond", 0, 0, PSI_DOCUMENT_ME},
13678 { &key_source_info_rotate_cond, "Source_info::rotate_cond", 0, 0, PSI_DOCUMENT_ME},
13679 { &key_relay_log_info_data_cond, "Relay_log_info::data_cond", 0, 0, PSI_DOCUMENT_ME},
13680 { &key_relay_log_info_log_space_cond, "Relay_log_info::log_space_cond", 0, 0, PSI_DOCUMENT_ME},
13681 { &key_relay_log_info_start_cond, "Relay_log_info::start_cond", 0, 0, PSI_DOCUMENT_ME},
13682 { &key_relay_log_info_stop_cond, "Relay_log_info::stop_cond", 0, 0, PSI_DOCUMENT_ME},
13683 { &key_relay_log_info_sleep_cond, "Relay_log_info::sleep_cond", 0, 0, PSI_DOCUMENT_ME},
13684 { &key_cond_slave_parallel_pend_jobs, "Relay_log_info::pending_jobs_cond", 0, 0, PSI_DOCUMENT_ME},
13685 { &key_cond_slave_parallel_worker, "Worker_info::jobs_cond", 0, 0, PSI_DOCUMENT_ME},
13686 { &key_cond_mta_gaq, "Relay_log_info::mta_gaq_cond", 0, 0, PSI_DOCUMENT_ME},
13687 { &key_gtid_ensure_index_cond, "Gtid_state", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13688 { &key_COND_compress_gtid_table, "COND_compress_gtid_table", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13689 { &key_commit_order_manager_cond, "Commit_order_manager::m_workers.cond", 0, 0, PSI_DOCUMENT_ME},
13690 { &key_cond_slave_worker_hash, "Relay_log_info::replica_worker_hash_cond", 0, 0, PSI_DOCUMENT_ME},
13691 { &key_monitor_info_run_cond, "Source_IO_monitor::run_cond", 0, 0, PSI_DOCUMENT_ME},
13692 { &key_COND_delegate_connection_cond_var, "THD::COND_delegate_connection_cond_var", 0, 0, PSI_DOCUMENT_ME},
13693 { &key_COND_group_replication_connection_cond_var, "THD::COND_group_replication_connection_cond_var", 0, 0, PSI_DOCUMENT_ME}
13694 #ifdef WITH_WSREP
13695 ,
13696 { &key_COND_wsrep_ready, "COND_wsrep_ready", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13697 { &key_COND_wsrep_sst, "COND_wsrep_sst", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13698 { &key_COND_wsrep_sst_init, "COND_wsrep_sst_init", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13699 { &key_COND_wsrep_replaying, "COND_wsrep_replaying", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13700 { &key_COND_wsrep_slave_threads, "COND_wsrep_slave_threads", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13701
13702 { &key_COND_wsrep_thd, "THD::COND_wsrep_thd", 0, 0, PSI_DOCUMENT_ME},
13703 { &key_COND_wsrep_sst_thread, "COND_wsrep_sst_thread", 0, 0, PSI_DOCUMENT_ME},
13704
13705 { &key_COND_wsrep_thd_queue, "COND_wsrep_thd_queue", 0, 0, PSI_DOCUMENT_ME},
13706 { &key_COND_wsrep_group_commit, "COND_wsrep_group_commit", 0, 0, PSI_DOCUMENT_ME}
13707 #endif /* WITH_WSREP */
13708 };
13709 /* clang-format on */
13710
13711 PSI_thread_key key_thread_bootstrap;
13712 PSI_thread_key key_thread_handle_manager;
13713 PSI_thread_key key_thread_one_connection;
13714 PSI_thread_key key_thread_compress_gtid_table;
13715 PSI_thread_key key_thread_parser_service;
13716 PSI_thread_key key_thread_handle_con_admin_sockets;
13717 #ifdef WITH_WSREP
13718 PSI_thread_key key_THREAD_wsrep_sst_joiner;
13719 PSI_thread_key key_THREAD_wsrep_sst_donor;
13720 PSI_thread_key key_THREAD_wsrep_sst_logger;
13721
13722 PSI_thread_key key_THREAD_wsrep_applier;
13723 PSI_thread_key key_THREAD_wsrep_rollbacker;
13724 PSI_thread_key key_THREAD_wsrep_post_rollbacker;
13725 #endif /* WITH_WSREP */
13726
13727 /* clang-format off */
13728 static PSI_thread_info all_server_threads[]=
13729 {
13730 #if defined (_WIN32)
13731 { &key_thread_handle_con_namedpipes, "con_named_pipes", "con_pipe", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13732 { &key_thread_handle_con_sharedmem, "con_shared_mem", "con_shm", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13733 { &key_thread_handle_con_sockets, "con_sockets", "con_sock", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13734 { &key_thread_handle_shutdown_restart, "shutdown_restart", "down_up", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13735 #endif /* _WIN32 */
13736 { &key_thread_bootstrap, "bootstrap", "boot", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13737 { &key_thread_handle_manager, "manager", "handle_mgr", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13738 { &key_thread_main, "main", "main", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13739 { &key_thread_one_connection, "one_connection", "connection",
13740 PSI_FLAG_USER | PSI_FLAG_NO_SEQNUM, 0, PSI_DOCUMENT_ME},
13741 { &key_thread_signal_hand, "signal_handler", "sig_handler", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13742 { &key_thread_compress_gtid_table, "compress_gtid_table", "gtid_zip", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13743 { &key_thread_parser_service, "parser_service", "parser_srv", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13744 { &key_thread_handle_con_admin_sockets, "admin_interface", "con_admin", PSI_FLAG_USER, 0, PSI_DOCUMENT_ME},
13745 #ifdef WITH_WSREP
13746 { &key_THREAD_wsrep_sst_joiner, "THREAD_wsrep_sst_joiner", "sst_joiner", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13747 { &key_THREAD_wsrep_sst_donor, "THREAD_wsrep_sst_donor", "sst_donor", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13748 { &key_THREAD_wsrep_sst_logger, "THREAD_wsrep_sst_logger", "sst_logger", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13749 { &key_THREAD_wsrep_applier, "THREAD_wsrep_applier", "applier", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13750 { &key_THREAD_wsrep_rollbacker, "THREAD_wsrep_rollbacker", "rlb", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
13751 { &key_THREAD_wsrep_post_rollbacker, "THREAD_wsrep_post_rollbacker", "postrlb", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME}
13752 #endif /* WITH_WSREP */
13753 };
13754 /* clang-format on */
13755
13756 PSI_file_key key_file_binlog;
13757 PSI_file_key key_file_binlog_index;
13758 PSI_file_key key_file_dbopt;
13759 PSI_file_key key_file_ERRMSG;
13760 PSI_file_key key_select_to_file;
13761 PSI_file_key key_file_fileparser;
13762 PSI_file_key key_file_frm;
13763 PSI_file_key key_file_load;
13764 PSI_file_key key_file_loadfile;
13765 PSI_file_key key_file_log_event_data;
13766 PSI_file_key key_file_log_event_info;
13767 PSI_file_key key_file_misc;
13768 PSI_file_key key_file_tclog;
13769 PSI_file_key key_file_trg;
13770 PSI_file_key key_file_trn;
13771 PSI_file_key key_file_init;
13772 PSI_file_key key_file_general_log;
13773 PSI_file_key key_file_slow_log;
13774 PSI_file_key key_file_relaylog;
13775 PSI_file_key key_file_relaylog_cache;
13776 PSI_file_key key_file_relaylog_index;
13777 PSI_file_key key_file_relaylog_index_cache;
13778 PSI_file_key key_file_sdi;
13779 PSI_file_key key_file_hash_join;
13780
13781 #ifdef WITH_WSREP
13782 PSI_file_key key_file_wsrep_gra_log;
13783 #endif /* WITH_WSREP */
13784
13785 /* clang-format off */
13786 static PSI_file_info all_server_files[]=
13787 {
13788 { &key_file_binlog, "binlog", 0, 0, PSI_DOCUMENT_ME},
13789 { &key_file_binlog_cache, "binlog_cache", 0, 0, PSI_DOCUMENT_ME},
13790 { &key_file_binlog_index, "binlog_index", 0, 0, PSI_DOCUMENT_ME},
13791 { &key_file_binlog_index_cache, "binlog_index_cache", 0, 0, PSI_DOCUMENT_ME},
13792 { &key_file_relaylog, "relaylog", 0, 0, PSI_DOCUMENT_ME},
13793 { &key_file_relaylog_cache, "relaylog_cache", 0, 0, PSI_DOCUMENT_ME},
13794 { &key_file_relaylog_index, "relaylog_index", 0, 0, PSI_DOCUMENT_ME},
13795 { &key_file_relaylog_index_cache, "relaylog_index_cache", 0, 0, PSI_DOCUMENT_ME},
13796 { &key_file_io_cache, "io_cache", 0, 0, PSI_DOCUMENT_ME},
13797 { &key_file_casetest, "casetest", 0, 0, PSI_DOCUMENT_ME},
13798 { &key_file_dbopt, "dbopt", 0, 0, PSI_DOCUMENT_ME},
13799 { &key_file_ERRMSG, "ERRMSG", 0, 0, PSI_DOCUMENT_ME},
13800 { &key_select_to_file, "select_to_file", 0, 0, PSI_DOCUMENT_ME},
13801 { &key_file_fileparser, "file_parser", 0, 0, PSI_DOCUMENT_ME},
13802 { &key_file_frm, "FRM", 0, 0, PSI_DOCUMENT_ME},
13803 { &key_file_load, "load", 0, 0, PSI_DOCUMENT_ME},
13804 { &key_file_loadfile, "LOAD_FILE", 0, 0, PSI_DOCUMENT_ME},
13805 { &key_file_log_event_data, "log_event_data", 0, 0, PSI_DOCUMENT_ME},
13806 { &key_file_log_event_info, "log_event_info", 0, 0, PSI_DOCUMENT_ME},
13807 { &key_file_misc, "misc", 0, 0, PSI_DOCUMENT_ME},
13808 { &key_file_pid, "pid", 0, 0, PSI_DOCUMENT_ME},
13809 { &key_file_general_log, "query_log", 0, 0, PSI_DOCUMENT_ME},
13810 { &key_file_slow_log, "slow_log", 0, 0, PSI_DOCUMENT_ME},
13811 { &key_file_tclog, "tclog", 0, 0, PSI_DOCUMENT_ME},
13812 { &key_file_trg, "trigger_name", 0, 0, PSI_DOCUMENT_ME},
13813 { &key_file_trn, "trigger", 0, 0, PSI_DOCUMENT_ME},
13814 { &key_file_init, "init", 0, 0, PSI_DOCUMENT_ME},
13815 { &key_file_sdi, "SDI", 0, 0, PSI_DOCUMENT_ME},
13816 { &key_file_hash_join, "hash_join", 0, 0, PSI_DOCUMENT_ME}
13817 #ifdef WITH_WSREP
13818 ,{ &key_file_wsrep_gra_log, "wsrep_gra_log", 0, 0, PSI_DOCUMENT_ME}
13819 #endif /* WITH_WSREP */
13820 };
13821 /* clang-format on */
13822 #endif /* HAVE_PSI_INTERFACE */
13823
13824 /* clang-format off */
13825 PSI_stage_info stage_after_create= { 0, "After create", 0, PSI_DOCUMENT_ME};
13826 PSI_stage_info stage_alter_inplace_prepare= { 0, "preparing for alter table", 0, PSI_DOCUMENT_ME};
13827 PSI_stage_info stage_alter_inplace= { 0, "altering table", 0, PSI_DOCUMENT_ME};
13828 PSI_stage_info stage_alter_inplace_commit= { 0, "committing alter table to storage engine", 0, PSI_DOCUMENT_ME};
13829 PSI_stage_info stage_changing_source= { 0, "Changing replication source", 0, PSI_DOCUMENT_ME};
13830 PSI_stage_info stage_checking_source_version= { 0, "Checking source version", 0, PSI_DOCUMENT_ME};
13831 PSI_stage_info stage_checking_permissions= { 0, "checking permissions", 0, PSI_DOCUMENT_ME};
13832 PSI_stage_info stage_cleaning_up= { 0, "cleaning up", 0, PSI_DOCUMENT_ME};
13833 PSI_stage_info stage_closing_tables= { 0, "closing tables", 0, PSI_DOCUMENT_ME};
13834 PSI_stage_info stage_compressing_gtid_table= { 0, "Compressing gtid_executed table", 0, PSI_DOCUMENT_ME};
13835 PSI_stage_info stage_connecting_to_source= { 0, "Connecting to source", 0, PSI_DOCUMENT_ME};
13836 PSI_stage_info stage_converting_heap_to_ondisk= { 0, "converting HEAP to ondisk", 0, PSI_DOCUMENT_ME};
13837 PSI_stage_info stage_copy_to_tmp_table= { 0, "copy to tmp table", PSI_FLAG_STAGE_PROGRESS, PSI_DOCUMENT_ME};
13838 PSI_stage_info stage_creating_table= { 0, "creating table", 0, PSI_DOCUMENT_ME};
13839 PSI_stage_info stage_creating_tmp_table= { 0, "Creating tmp table", 0, PSI_DOCUMENT_ME};
13840 PSI_stage_info stage_deleting_from_main_table= { 0, "deleting from main table", 0, PSI_DOCUMENT_ME};
13841 PSI_stage_info stage_deleting_from_reference_tables= { 0, "deleting from reference tables", 0, PSI_DOCUMENT_ME};
13842 PSI_stage_info stage_discard_or_import_tablespace= { 0, "discard_or_import_tablespace", 0, PSI_DOCUMENT_ME};
13843 PSI_stage_info stage_end= { 0, "end", 0, PSI_DOCUMENT_ME};
13844 PSI_stage_info stage_executing= { 0, "executing", 0, PSI_DOCUMENT_ME};
13845 PSI_stage_info stage_execution_of_init_command= { 0, "Execution of init_command", 0, PSI_DOCUMENT_ME};
13846 PSI_stage_info stage_explaining= { 0, "explaining", 0, PSI_DOCUMENT_ME};
13847 PSI_stage_info stage_finished_reading_one_binlog_switching_to_next_binlog= { 0, "Finished reading one binlog; switching to next binlog", 0, PSI_DOCUMENT_ME};
13848 PSI_stage_info stage_flushing_relay_log_and_source_info_repository= { 0, "Flushing relay log and source info repository.", 0, PSI_DOCUMENT_ME};
13849 PSI_stage_info stage_flushing_relay_log_info_file= { 0, "Flushing relay-log info file.", 0, PSI_DOCUMENT_ME};
13850 PSI_stage_info stage_freeing_items= { 0, "freeing items", 0, PSI_DOCUMENT_ME};
13851 PSI_stage_info stage_fulltext_initialization= { 0, "FULLTEXT initialization", 0, PSI_DOCUMENT_ME};
13852 PSI_stage_info stage_init= { 0, "init", 0, PSI_DOCUMENT_ME};
13853 PSI_stage_info stage_killing_replica= { 0, "Killing replica", 0, PSI_DOCUMENT_ME};
13854 PSI_stage_info stage_logging_slow_query= { 0, "logging slow query", 0, PSI_DOCUMENT_ME};
13855 PSI_stage_info stage_making_temp_file_append_before_load_data= { 0, "Making temporary file (append) before replaying LOAD DATA INFILE", 0, PSI_DOCUMENT_ME};
13856 PSI_stage_info stage_manage_keys= { 0, "manage keys", 0, PSI_DOCUMENT_ME};
13857 PSI_stage_info stage_source_has_sent_all_binlog_to_replica= { 0, "Source has sent all binlog to replica; waiting for more updates", 0, PSI_DOCUMENT_ME};
13858 PSI_stage_info stage_opening_tables= { 0, "Opening tables", 0, PSI_DOCUMENT_ME};
13859 PSI_stage_info stage_optimizing= { 0, "optimizing", 0, PSI_DOCUMENT_ME};
13860 PSI_stage_info stage_preparing= { 0, "preparing", 0, PSI_DOCUMENT_ME};
13861 PSI_stage_info stage_purging_old_relay_logs= { 0, "Purging old relay logs", 0, PSI_DOCUMENT_ME};
13862 PSI_stage_info stage_query_end= { 0, "query end", 0, PSI_DOCUMENT_ME};
13863 PSI_stage_info stage_queueing_source_event_to_the_relay_log= { 0, "Queueing source event to the relay log", 0, PSI_DOCUMENT_ME};
13864 PSI_stage_info stage_reading_event_from_the_relay_log= { 0, "Reading event from the relay log", 0, PSI_DOCUMENT_ME};
13865 PSI_stage_info stage_registering_replica_on_source= { 0, "Registering replica on source", 0, PSI_DOCUMENT_ME};
13866 PSI_stage_info stage_removing_tmp_table= { 0, "removing tmp table", 0, PSI_DOCUMENT_ME};
13867 PSI_stage_info stage_rename= { 0, "rename", 0, PSI_DOCUMENT_ME};
13868 PSI_stage_info stage_rename_result_table= { 0, "rename result table", 0, PSI_DOCUMENT_ME};
13869 PSI_stage_info stage_requesting_binlog_dump= { 0, "Requesting binlog dump", 0, PSI_DOCUMENT_ME};
13870 PSI_stage_info stage_searching_rows_for_update= { 0, "Searching rows for update", 0, PSI_DOCUMENT_ME};
13871 PSI_stage_info stage_sending_binlog_event_to_replica= { 0, "Sending binlog event to replica", 0, PSI_DOCUMENT_ME};
13872 PSI_stage_info stage_setup= { 0, "setup", 0, PSI_DOCUMENT_ME};
13873 PSI_stage_info stage_replica_has_read_all_relay_log= { 0, "Replica has read all relay log; waiting for more updates", 0, PSI_DOCUMENT_ME};
13874 PSI_stage_info stage_replica_reconnecting_after_failed_binlog_dump_request{ 0, "Reconnecting after a failed binlog dump request", 0, PSI_DOCUMENT_ME};
13875 PSI_stage_info stage_replica_reconnecting_after_failed_event_read{ 0, "Reconnecting after a failed source event read", 0, PSI_DOCUMENT_ME};
13876 PSI_stage_info stage_replica_reconnecting_after_failed_registration_on_source{ 0, "Reconnecting after a failed registration on source", 0, PSI_DOCUMENT_ME};
13877 PSI_stage_info stage_replica_waiting_event_from_coordinator= { 0, "Waiting for an event from Coordinator", 0, PSI_DOCUMENT_ME};
13878 PSI_stage_info stage_replica_waiting_for_workers_to_process_queue= { 0, "Waiting for replica workers to process their queues", 0, PSI_DOCUMENT_ME};
13879 PSI_stage_info stage_replica_waiting_to_reconnect_after_failed_binlog_dump_request{ 0, "Waiting to reconnect after a failed binlog dump request", 0, PSI_DOCUMENT_ME};
13880 PSI_stage_info stage_replica_waiting_to_reconnect_after_failed_event_read{ 0, "Waiting to reconnect after a failed source event read", 0, PSI_DOCUMENT_ME};
13881 PSI_stage_info stage_replica_waiting_to_reconnect_after_failed_registration_on_source{ 0, "Waiting to reconnect after a failed registration on source", 0, PSI_DOCUMENT_ME};
13882 PSI_stage_info stage_replica_waiting_worker_queue= { 0, "Waiting for Replica Worker queue", 0, PSI_DOCUMENT_ME};
13883 PSI_stage_info stage_replica_waiting_worker_to_free_events= { 0, "Waiting for Replica Workers to free pending events", 0, PSI_DOCUMENT_ME};
13884 PSI_stage_info stage_replica_waiting_worker_to_release_partition= { 0, "Waiting for Replica Worker to release partition", 0, PSI_DOCUMENT_ME};
13885 PSI_stage_info stage_replica_waiting_workers_to_exit= { 0, "Waiting for workers to exit", 0, PSI_DOCUMENT_ME};
13886 PSI_stage_info stage_rpl_apply_row_evt_write= { 0, "Applying batch of row changes (write)", PSI_FLAG_STAGE_PROGRESS, PSI_DOCUMENT_ME};
13887 PSI_stage_info stage_rpl_apply_row_evt_update= { 0, "Applying batch of row changes (update)", PSI_FLAG_STAGE_PROGRESS, PSI_DOCUMENT_ME};
13888 PSI_stage_info stage_rpl_apply_row_evt_delete= { 0, "Applying batch of row changes (delete)", PSI_FLAG_STAGE_PROGRESS, PSI_DOCUMENT_ME};
13889 PSI_stage_info stage_statistics= { 0, "statistics", 0, PSI_DOCUMENT_ME};
13890 PSI_stage_info stage_sql_thd_waiting_until_delay= { 0, "Waiting until SOURCE_DELAY seconds after source executed event", 0, PSI_DOCUMENT_ME};
13891 PSI_stage_info stage_system_lock= { 0, "System lock", 0, PSI_DOCUMENT_ME};
13892 PSI_stage_info stage_update= { 0, "update", 0, PSI_DOCUMENT_ME};
13893 PSI_stage_info stage_updating= { 0, "updating", 0, PSI_DOCUMENT_ME};
13894 PSI_stage_info stage_updating_main_table= { 0, "updating main table", 0, PSI_DOCUMENT_ME};
13895 PSI_stage_info stage_updating_reference_tables= { 0, "updating reference tables", 0, PSI_DOCUMENT_ME};
13896 PSI_stage_info stage_user_sleep= { 0, "User sleep", 0, PSI_DOCUMENT_ME};
13897 PSI_stage_info stage_verifying_table= { 0, "verifying table", 0, PSI_DOCUMENT_ME};
13898 PSI_stage_info stage_waiting_for_gtid_to_be_committed= { 0, "Waiting for GTID to be committed", 0, PSI_DOCUMENT_ME};
13899 PSI_stage_info stage_waiting_for_handler_commit= { 0, "waiting for handler commit", 0, PSI_DOCUMENT_ME};
13900 PSI_stage_info stage_waiting_for_source_to_send_event= { 0, "Waiting for source to send event", 0, PSI_DOCUMENT_ME};
13901 PSI_stage_info stage_waiting_for_source_update= { 0, "Waiting for source update", 0, PSI_DOCUMENT_ME};
13902 PSI_stage_info stage_waiting_for_relay_log_space= { 0, "Waiting for the replica SQL thread to free relay log space", 0, PSI_DOCUMENT_ME};
13903 PSI_stage_info stage_waiting_for_replica_mutex_on_exit= { 0, "Waiting for replica mutex on exit", 0, PSI_DOCUMENT_ME};
13904 PSI_stage_info stage_waiting_for_replica_thread_to_start= { 0, "Waiting for replica thread to start", 0, PSI_DOCUMENT_ME};
13905 PSI_stage_info stage_waiting_for_table_flush= { 0, "Waiting for table flush", 0, PSI_DOCUMENT_ME};
13906 PSI_stage_info stage_waiting_for_the_next_event_in_relay_log= { 0, "Waiting for the next event in relay log", 0, PSI_DOCUMENT_ME};
13907 PSI_stage_info stage_waiting_for_the_replica_thread_to_advance_position= { 0, "Waiting for the replica SQL thread to advance position", 0, PSI_DOCUMENT_ME};
13908 PSI_stage_info stage_waiting_to_finalize_termination= { 0, "Waiting to finalize termination", 0, PSI_DOCUMENT_ME};
13909 PSI_stage_info stage_worker_waiting_for_its_turn_to_commit= { 0, "Waiting for preceding transaction to commit", 0, PSI_DOCUMENT_ME};
13910 PSI_stage_info stage_worker_waiting_for_commit_parent= { 0, "Waiting for dependent transaction to commit", 0, PSI_DOCUMENT_ME};
13911 PSI_stage_info stage_suspending= { 0, "Suspending", 0, PSI_DOCUMENT_ME};
13912 PSI_stage_info stage_starting= { 0, "starting", 0, PSI_DOCUMENT_ME};
13913 PSI_stage_info stage_waiting_for_no_channel_reference= { 0, "Waiting for no channel reference.", 0, PSI_DOCUMENT_ME};
13914 PSI_stage_info stage_hook_begin_trans= { 0, "Executing hook on transaction begin.", 0, PSI_DOCUMENT_ME};
13915 PSI_stage_info stage_binlog_transaction_compress= { 0, "Compressing transaction changes.", 0, PSI_DOCUMENT_ME};
13916 PSI_stage_info stage_binlog_transaction_decompress= { 0, "Decompressing transaction changes.", 0, PSI_DOCUMENT_ME};
13917 PSI_stage_info stage_rpl_failover_fetching_source_member_details= { 0, "Fetching source member details from connected source", 0, PSI_DOCUMENT_ME};
13918 PSI_stage_info stage_rpl_failover_updating_source_member_details= { 0, "Updating fetched source member details on receiver", 0, PSI_DOCUMENT_ME};
13919 PSI_stage_info stage_rpl_failover_wait_before_next_fetch= { 0, "Wait before trying to fetch next membership changes from source", 0, PSI_DOCUMENT_ME};
13920 PSI_stage_info stage_communication_delegation= { 0, "Connection delegated to Group Replication", 0, PSI_DOCUMENT_ME};
13921 PSI_stage_info stage_restoring_secondary_keys= { 0, "restoring secondary keys", 0, PSI_DOCUMENT_ME};
13922 /* clang-format on */
13923
13924 extern PSI_stage_info stage_waiting_for_disk_space;
13925
13926 #ifdef WITH_WSREP
13927 PSI_stage_info stage_wsrep_writing_rows = {0, "wsrep: writing rows", 0,
13928 PSI_DOCUMENT_ME};
13929 PSI_stage_info stage_wsrep_deleting_rows = {0, "wsrep: deleting rows", 0,
13930 PSI_DOCUMENT_ME};
13931 PSI_stage_info stage_wsrep_updating_rows = {0, "wsrep: updating rows", 0,
13932 PSI_DOCUMENT_ME};
13933
13934 PSI_stage_info stage_wsrep_applying_writeset = {0, "wsrep: applying write set",
13935 0, PSI_DOCUMENT_ME};
13936 PSI_stage_info stage_wsrep_applied_writeset = {0, "wsrep: applied write set", 0,
13937 PSI_DOCUMENT_ME};
13938
13939 PSI_stage_info stage_wsrep_applying_toi_writeset = {
13940 0, "wsrep: applying TOI write set", 0, PSI_DOCUMENT_ME};
13941 PSI_stage_info stage_wsrep_applied_toi_writeset = {
13942 0, "wsrep: applied TOI write set", 0, PSI_DOCUMENT_ME};
13943
13944 PSI_stage_info stage_wsrep_committing = {0, "wsrep: committing write set", 0,
13945 PSI_DOCUMENT_ME};
13946 PSI_stage_info stage_wsrep_committed = {0, "wsrep: committed write set", 0,
13947 PSI_DOCUMENT_ME};
13948
13949 PSI_stage_info stage_wsrep_toi_committing = {
13950 0, "wsrep: committing TOI write set", 0, PSI_DOCUMENT_ME};
13951 PSI_stage_info stage_wsrep_toi_committed = {0, "wsrep: TOI committed write set",
13952 0, PSI_DOCUMENT_ME};
13953
13954 PSI_stage_info stage_wsrep_rolling_back = {0, "wsrep: rolling back", 0,
13955 PSI_DOCUMENT_ME};
13956 PSI_stage_info stage_wsrep_rolled_back = {0, "wsrep: rolled back", 0,
13957 PSI_DOCUMENT_ME};
13958
13959 PSI_stage_info stage_wsrep_replicating_commit = {
13960 0, "wsrep: replicating and certifying write set", 0, PSI_DOCUMENT_ME};
13961 PSI_stage_info stage_wsrep_write_set_replicated = {
13962 0, "wsrep: write-set replicated and certified", 0, PSI_DOCUMENT_ME};
13963
13964 PSI_stage_info stage_wsrep_replaying_trx = {0, "wsrep: replaying transaction",
13965 0, PSI_DOCUMENT_ME};
13966 PSI_stage_info stage_wsrep_replayed_write_set = {0, "wsrep: replayed write set",
13967 0, PSI_DOCUMENT_ME};
13968
13969 PSI_stage_info stage_wsrep_preparing_for_TO_isolation = {
13970 0, "wsrep: preparing for TO isolation", 0, PSI_DOCUMENT_ME};
13971 PSI_stage_info stage_wsrep_TO_isolation_initiated = {
13972 0, "wsrep: TO isolation initiated", 0, PSI_DOCUMENT_ME};
13973 PSI_stage_info stage_wsrep_completed_TO_isolation = {
13974 0, "wsrep: completed TO isolation", 0, PSI_DOCUMENT_ME};
13975
13976 PSI_stage_info stage_wsrep_applier_idle = {0, "wsrep: applier idle", 0,
13977 PSI_DOCUMENT_ME};
13978 PSI_stage_info stage_wsrep_in_rollback_thread = {0, "wsrep: in rollback thread",
13979 0, PSI_DOCUMENT_ME};
13980 PSI_stage_info stage_wsrep_aborter_idle = {0, "wsrep: aborter idle", 0,
13981 PSI_DOCUMENT_ME};
13982 PSI_stage_info stage_wsrep_aborter_active = {0, "wsrep: aborter active", 0,
13983 PSI_DOCUMENT_ME};
13984
13985 #endif /* WITH_WSREP */
13986
13987 #ifdef HAVE_PSI_INTERFACE
13988
13989 PSI_stage_info *all_server_stages[] = {
13990 &stage_after_create,
13991 &stage_alter_inplace_prepare,
13992 &stage_alter_inplace,
13993 &stage_alter_inplace_commit,
13994 &stage_changing_source,
13995 &stage_checking_source_version,
13996 &stage_checking_permissions,
13997 &stage_cleaning_up,
13998 &stage_closing_tables,
13999 &stage_compressing_gtid_table,
14000 &stage_connecting_to_source,
14001 &stage_converting_heap_to_ondisk,
14002 &stage_copy_to_tmp_table,
14003 &stage_creating_table,
14004 &stage_creating_tmp_table,
14005 &stage_deleting_from_main_table,
14006 &stage_deleting_from_reference_tables,
14007 &stage_discard_or_import_tablespace,
14008 &stage_end,
14009 &stage_executing,
14010 &stage_execution_of_init_command,
14011 &stage_explaining,
14012 &stage_finished_reading_one_binlog_switching_to_next_binlog,
14013 &stage_flushing_relay_log_and_source_info_repository,
14014 &stage_flushing_relay_log_info_file,
14015 &stage_freeing_items,
14016 &stage_fulltext_initialization,
14017 &stage_init,
14018 &stage_killing_replica,
14019 &stage_logging_slow_query,
14020 &stage_making_temp_file_append_before_load_data,
14021 &stage_manage_keys,
14022 &stage_source_has_sent_all_binlog_to_replica,
14023 &stage_opening_tables,
14024 &stage_optimizing,
14025 &stage_preparing,
14026 &stage_purging_old_relay_logs,
14027 &stage_query_end,
14028 &stage_queueing_source_event_to_the_relay_log,
14029 &stage_reading_event_from_the_relay_log,
14030 &stage_registering_replica_on_source,
14031 &stage_removing_tmp_table,
14032 &stage_rename,
14033 &stage_rename_result_table,
14034 &stage_requesting_binlog_dump,
14035 &stage_searching_rows_for_update,
14036 &stage_sending_binlog_event_to_replica,
14037 &stage_setup,
14038 &stage_replica_has_read_all_relay_log,
14039 &stage_replica_reconnecting_after_failed_binlog_dump_request,
14040 &stage_replica_reconnecting_after_failed_event_read,
14041 &stage_replica_reconnecting_after_failed_registration_on_source,
14042 &stage_replica_waiting_event_from_coordinator,
14043 &stage_replica_waiting_for_workers_to_process_queue,
14044 &stage_replica_waiting_worker_queue,
14045 &stage_replica_waiting_to_reconnect_after_failed_binlog_dump_request,
14046 &stage_replica_waiting_to_reconnect_after_failed_event_read,
14047 &stage_replica_waiting_to_reconnect_after_failed_registration_on_source,
14048 &stage_replica_waiting_worker_to_free_events,
14049 &stage_replica_waiting_worker_to_release_partition,
14050 &stage_replica_waiting_workers_to_exit,
14051 &stage_rpl_apply_row_evt_write,
14052 &stage_rpl_apply_row_evt_update,
14053 &stage_rpl_apply_row_evt_delete,
14054 &stage_sql_thd_waiting_until_delay,
14055 &stage_statistics,
14056 &stage_system_lock,
14057 &stage_update,
14058 &stage_updating,
14059 &stage_updating_main_table,
14060 &stage_updating_reference_tables,
14061 &stage_user_sleep,
14062 &stage_verifying_table,
14063 &stage_waiting_for_gtid_to_be_committed,
14064 &stage_waiting_for_handler_commit,
14065 &stage_waiting_for_source_to_send_event,
14066 &stage_waiting_for_source_update,
14067 &stage_waiting_for_relay_log_space,
14068 &stage_waiting_for_replica_mutex_on_exit,
14069 &stage_waiting_for_replica_thread_to_start,
14070 &stage_waiting_for_table_flush,
14071 &stage_waiting_for_the_next_event_in_relay_log,
14072 &stage_waiting_for_the_replica_thread_to_advance_position,
14073 &stage_waiting_to_finalize_termination,
14074 &stage_worker_waiting_for_its_turn_to_commit,
14075 &stage_worker_waiting_for_commit_parent,
14076 &stage_suspending,
14077 &stage_starting,
14078 &stage_waiting_for_no_channel_reference,
14079 &stage_hook_begin_trans,
14080 &stage_waiting_for_disk_space,
14081 &stage_binlog_transaction_compress,
14082 &stage_binlog_transaction_decompress,
14083 &stage_rpl_failover_fetching_source_member_details,
14084 &stage_rpl_failover_updating_source_member_details,
14085 &stage_rpl_failover_wait_before_next_fetch,
14086 &stage_communication_delegation,
14087 &stage_restoring_secondary_keys};
14088
14089 /* clang-format off */
14090 #ifdef WITH_WSREP
14091 PSI_stage_info *wsrep_server_stages[] = {
14092 // log_event
14093 &stage_wsrep_writing_rows,
14094 &stage_wsrep_deleting_rows,
14095 &stage_wsrep_updating_rows,
14096
14097 // wsrep_applier
14098 &stage_wsrep_applying_writeset,
14099 &stage_wsrep_applied_writeset,
14100
14101 &stage_wsrep_applying_toi_writeset,
14102 &stage_wsrep_applied_toi_writeset,
14103
14104 &stage_wsrep_committing,
14105 &stage_wsrep_committed,
14106
14107 &stage_wsrep_toi_committing,
14108 &stage_wsrep_toi_committed,
14109
14110 &stage_wsrep_rolling_back,
14111 &stage_wsrep_rolled_back,
14112
14113 &stage_wsrep_replicating_commit,
14114 &stage_wsrep_write_set_replicated,
14115
14116 &stage_wsrep_replaying_trx,
14117 &stage_wsrep_replayed_write_set,
14118
14119 // wsrep_mysqld
14120 &stage_wsrep_preparing_for_TO_isolation,
14121 &stage_wsrep_TO_isolation_initiated,
14122 &stage_wsrep_completed_TO_isolation,
14123
14124 // wsrep_thd
14125 &stage_wsrep_applier_idle,
14126 &stage_wsrep_in_rollback_thread,
14127 &stage_wsrep_aborter_idle,
14128 &stage_wsrep_aborter_active};
14129
14130 #endif /* WITH_WSREP */
14131 /* clang-format on */
14132
14133 PSI_socket_key key_socket_tcpip;
14134 PSI_socket_key key_socket_unix;
14135 PSI_socket_key key_socket_client_connection;
14136
14137 /* clang-format off */
14138 static PSI_socket_info all_server_sockets[]=
14139 {
14140 { &key_socket_tcpip, "server_tcpip_socket", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
14141 { &key_socket_unix, "server_unix_socket", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
14142 { &key_socket_client_connection, "client_connection", PSI_FLAG_USER, 0, PSI_DOCUMENT_ME}
14143 };
14144 /* clang-format on */
14145
14146 /* TODO: find a good header */
14147 void init_client_psi_keys(void);
14148
14149 /**
14150 Initialise all the performance schema instrumentation points
14151 used by the server.
14152 */
14153 9813 static void init_server_psi_keys(void) {
14154 9813 const char *category = "sql";
14155 int count;
14156
14157 9813 count = static_cast<int>(array_elements(all_server_mutexes));
14158 9813 mysql_mutex_register(category, all_server_mutexes, count);
14159
14160 9813 count = static_cast<int>(array_elements(all_server_rwlocks));
14161 9813 mysql_rwlock_register(category, all_server_rwlocks, count);
14162
14163 9813 count = static_cast<int>(array_elements(all_server_conds));
14164 9813 mysql_cond_register(category, all_server_conds, count);
14165
14166 9813 count = static_cast<int>(array_elements(all_server_threads));
14167 9813 mysql_thread_register(category, all_server_threads, count);
14168
14169 9813 count = static_cast<int>(array_elements(all_server_files));
14170 9813 mysql_file_register(category, all_server_files, count);
14171
14172 9813 count = static_cast<int>(array_elements(all_server_stages));
14173 9813 mysql_stage_register(category, all_server_stages, count);
14174
14175 9813 count = static_cast<int>(array_elements(all_server_sockets));
14176 9813 mysql_socket_register(category, all_server_sockets, count);
14177
14178 9813 register_server_memory_keys();
14179
14180 #ifdef WITH_WSREP
14181 9813 const char *wsrep_category = "wsrep";
14182 9813 count = array_elements(wsrep_server_stages);
14183 9813 mysql_stage_register(wsrep_category, wsrep_server_stages, count);
14184 #endif /* WITH_WSREP */
14185
14186 #ifdef HAVE_PSI_STATEMENT_INTERFACE
14187 9813 init_sql_statement_info();
14188
14189 /* Register [0 .. SQLCOM_CLONE - 1] as "statement/sql/..." */
14190 9813 count = (int)SQLCOM_CLONE;
14191 9813 mysql_statement_register(category, sql_statement_info, count);
14192
14193 /* Exclude SQLCOM_CLONE as it mutates and is registered as abstract. */
14194 9813 count = (int)SQLCOM_END - (int)SQLCOM_CLONE;
14195 9813 mysql_statement_register(category, &sql_statement_info[(int)SQLCOM_CLONE + 1],
14196 count);
14197 9813 category = "abstract";
14198 9813 mysql_statement_register(category, &sql_statement_info[(int)SQLCOM_CLONE], 1);
14199
14200 9813 init_sp_psi_keys();
14201
14202 9813 init_scheduler_psi_keys();
14203
14204 9813 category = "com";
14205 9813 init_com_statement_info();
14206
14207 /*
14208 Register [0 .. COM_QUERY - 1] as "statement/com/..."
14209 */
14210 9813 count = (int)COM_QUERY;
14211 9813 mysql_statement_register(category, com_statement_info, count);
14212
14213 /* Exclude COM_CLONE as it would mutate */
14214 9813 count = (int)COM_CLONE - (int)COM_QUERY - 1;
14215 9813 mysql_statement_register(category, &com_statement_info[(int)COM_QUERY + 1],
14216 count);
14217 /*
14218 Register [COM_CLONE + 1 .. COM_END] as "statement/com/..."
14219 */
14220 9813 count = (int)COM_END - (int)COM_CLONE;
14221 9813 mysql_statement_register(category, &com_statement_info[(int)COM_CLONE + 1],
14222 count);
14223 9813 category = "abstract";
14224 /*
14225 Register [COM_QUERY] as "statement/abstract/com_query"
14226 */
14227 9813 mysql_statement_register(category, &com_statement_info[(int)COM_QUERY], 1);
14228 9813 mysql_statement_register(category, &com_statement_info[(int)COM_CLONE], 1);
14229
14230 /*
14231 When a new packet is received,
14232 it is instrumented as "statement/abstract/new_packet".
14233 Based on the packet type found, it later mutates to the
14234 proper narrow type, for example
14235 "statement/abstract/query" or "statement/com/ping".
14236 In cases of "statement/abstract/query", SQL queries are given to
14237 the parser, which mutates the statement type to an even more
14238 narrow classification, for example "statement/sql/select".
14239 */
14240 9813 stmt_info_new_packet.m_key = 0;
14241 9813 stmt_info_new_packet.m_name = "new_packet";
14242 9813 stmt_info_new_packet.m_flags = PSI_FLAG_MUTABLE;
14243 9813 stmt_info_new_packet.m_documentation =
14244 "New packet just received from the network. "
14245 "At this point, the real command type is unknown, "
14246 "the type will be refined after reading the packet header.";
14247 9813 mysql_statement_register(category, &stmt_info_new_packet, 1);
14248
14249 /*
14250 Statements processed from the relay log are initially instrumented as
14251 "statement/abstract/relay_log". The parser will mutate the statement type to
14252 a more specific classification, for example "statement/sql/insert".
14253 */
14254 9813 stmt_info_rpl.m_key = 0;
14255 9813 stmt_info_rpl.m_name = "relay_log";
14256 9813 stmt_info_rpl.m_flags = PSI_FLAG_MUTABLE;
14257 9813 stmt_info_rpl.m_documentation =
14258 "New event just read from the relay log. "
14259 "At this point, the real statement type is unknown, "
14260 "the type will be refined after parsing the event.";
14261 9813 mysql_statement_register(category, &stmt_info_rpl, 1);
14262 #endif
14263
14264 /* Common client and server code. */
14265 9813 init_client_psi_keys();
14266 /* Vio */
14267 9813 init_vio_psi_keys();
14268 /* TLS interfaces */
14269 9813 init_tls_psi_keys();
14270 9813 }
14271 #endif /* HAVE_PSI_INTERFACE */
14272
14273 14996 bool do_create_native_table_for_pfs(THD *thd, const Plugin_table *t) {
14274 14996 const char *schema_name = t->get_schema_name();
14275 14996 const char *table_name = t->get_name();
14276 14996 MDL_request table_request;
14277
1/2
✓ Branch 0 taken 14996 times.
✗ Branch 1 not taken.
14996 MDL_REQUEST_INIT(&table_request, MDL_key::TABLE, schema_name, table_name,
14278 MDL_EXCLUSIVE, MDL_TRANSACTION);
14279
14280
2/4
✓ Branch 0 taken 14996 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 14996 times.
14996 if (thd->mdl_context.acquire_lock(&table_request,
14281 thd->variables.lock_wait_timeout)) {
14282 /* Error, failed to get MDL lock. */
14283 return true;
14284 }
14285
14286
1/2
✓ Branch 0 taken 14996 times.
✗ Branch 1 not taken.
14996 tdc_remove_table(thd, TDC_RT_REMOVE_ALL, schema_name, table_name, false);
14287
14288
2/4
✓ Branch 0 taken 14996 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 14996 times.
14996 if (dd::create_native_table(thd, t)) {
14289 /* Error, failed to create DD table. */
14290 return true;
14291 }
14292
14293 14996 return false;
14294 }
14295
14296 14997 bool create_native_table_for_pfs(const Plugin_table *t) {
14297 /* If InnoDB is not initialized yet, return error */
14298
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 14996 times.
14997 if (!is_builtin_and_core_se_initialized()) return true;
14299
14300 14996 THD *thd = current_thd;
14301
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14996 times.
14996 assert(thd);
14302 14996 return do_create_native_table_for_pfs(thd, t);
14303 }
14304
14305 9674 static bool do_drop_native_table_for_pfs(THD *thd, const char *schema_name,
14306 const char *table_name) {
14307 9674 MDL_request table_request;
14308
1/2
✓ Branch 0 taken 9674 times.
✗ Branch 1 not taken.
9674 MDL_REQUEST_INIT(&table_request, MDL_key::TABLE, schema_name, table_name,
14309 MDL_EXCLUSIVE, MDL_TRANSACTION);
14310
14311
3/4
✓ Branch 0 taken 9674 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 9673 times.
9674 if (thd->mdl_context.acquire_lock(&table_request,
14312 thd->variables.lock_wait_timeout)) {
14313 /* Error, failed to get MDL lock. */
14314 1 return true;
14315 }
14316
14317
1/2
✓ Branch 0 taken 9673 times.
✗ Branch 1 not taken.
9673 tdc_remove_table(thd, TDC_RT_REMOVE_ALL, schema_name, table_name, false);
14318
14319
2/4
✓ Branch 0 taken 9673 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9673 times.
9673 if (dd::drop_native_table(thd, schema_name, table_name)) {
14320 /* Error, failed to destroy DD table. */
14321 return true;
14322 }
14323
14324 9673 return false;
14325 }
14326
14327 22866 bool drop_native_table_for_pfs(const char *schema_name,
14328 const char *table_name) {
14329 /* If server is shutting down, by the time control reaches here, DD would have
14330 * already been shut down. Therefore return success and tables won't be
14331 * deleted and would be available at next server start.
14332 */
14333
2/2
✓ Branch 0 taken 13088 times.
✓ Branch 1 taken 9778 times.
22866 if (get_server_state() == SERVER_SHUTTING_DOWN) {
14334 13088 return false;
14335 }
14336
14337 /* During bootstrap error cleanup, we don't have THD. */
14338 9778 THD *thd = current_thd;
14339
2/2
✓ Branch 0 taken 104 times.
✓ Branch 1 taken 9674 times.
9778 if (thd == nullptr) {
14340
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 104 times.
104 assert(get_server_state() == SERVER_BOOTING);
14341 104 return false;
14342 }
14343 9674 return do_drop_native_table_for_pfs(thd, schema_name, table_name);
14344 }
14345
14346 #ifdef _WIN32
14347 // update_named_pipe_full_access_group returns false on success, true on failure
14348 bool update_named_pipe_full_access_group(const char *new_group_name) {
14349 if (named_pipe_acceptor) {
14350 return named_pipe_listener->update_named_pipe_full_access_group(
14351 new_group_name);
14352 }
14353 return true;
14354 }
14355
14356 #endif // _WIN32
14357
14358 /**
14359 Get status partial_revokes on server
14360
14361 @return a bool indicating partial_revokes status of the server.
14362 @retval true Parital revokes is ON
14363 @retval flase Partial revokes is OFF
14364 */
14365 639430 bool mysqld_partial_revokes() {
14366 639430 return partial_revokes.load(std::memory_order_relaxed);
14367 }
14368
14369 /**
14370 Set partial_revokes with a given value
14371
14372 @param value true or false indicating the status of partial revokes
14373 turned ON/OFF on server.
14374 */
14375 9953 void set_mysqld_partial_revokes(bool value) {
14376 9953 partial_revokes.store(value, std::memory_order_relaxed);
14377 9953 }
14378
14379 /**
14380 If there exists at least one restrictions on any user,
14381 then update global variables which track the partial_revokes.
14382
14383 @param thd THD handle
14384
14385 @return a bool indicating partial_revokes status of the server.
14386 @retval true Parital revokes exists; updated the global variables.
14387 @retval false Partial revokes does not exist.
14388 */
14389 12480 bool check_and_update_partial_revokes_sysvar(THD *thd) {
14390
2/2
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 12418 times.
12480 if (is_partial_revoke_exists(thd)) {
14391 62 MUTEX_LOCK(lock, &LOCK_partial_revokes);
14392
1/2
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
62 set_mysqld_partial_revokes(true);
14393 62 opt_partial_revokes = true;
14394 62 return true;
14395 62 }
14396 12418 return false;
14397 }
14398